GithubHelp home page GithubHelp logo

TypeError: Class constructor Type cannot be invoked without 'new' - nest runtime error when using angular library + mikro orm about ng-universal HOT 7 CLOSED

rat-matheson avatar rat-matheson commented on April 28, 2024
TypeError: Class constructor Type cannot be invoked without 'new' - nest runtime error when using angular library + mikro orm

from ng-universal.

Comments (7)

jmcdo29 avatar jmcdo29 commented on April 28, 2024

I can't start you repo because I can't install @ngx-tmp/bug-repo. NPM says it is not found

from ng-universal.

rat-matheson avatar rat-matheson commented on April 28, 2024

Thanks so much for taking a look at this. I've updated the nest application repository ( nest-mikro-bug ) to use the paths config in the tsconfig.json rather than the private npm repository I was using. You will need to do the following:

  1. get the updated nest-mikro-bug code - it will update the tsconfig.json and the package.json
  2. npm install
  3. switch to nest-mikro-bug-lib and build it-> ng build @ngx-tmp/bug-repo
  4. update the tsconfig.json for nest-mikro-bug to point to your output (in case your workspace has a different name than mine). You need to change this line - tsconfig.json#L22
  5. run nest start to start up nest

from ng-universal.

rat-matheson avatar rat-matheson commented on April 28, 2024

I tried something new. I built with nest, but than did the following:

  • installed module-alias so I could more clearly specify which bundle I wanted to use
  • ran using "node dist/main.js"

I was careful to use the umd module as this document says it is the format to use for node.js. The result was:

$ node dist/main.js
C:\Users\joelw\eclipse-workspace\tower-poi\packages\ngx-tmp\dist\ngx-tmp\bug-rep
o\bundles\ngx-tmp-bug-repo.umd.js:411
                var _this = _super.apply(this, __spreadArray([], __read(argument
s))) || this;
                                   ^

TypeError: Class constructor Type cannot be invoked without 'new'
    at new TransformType (C:\Users\joelw\eclipse-workspace\tower-poi\packages\ng
x-tmp\dist\ngx-tmp\bug-repo\bundles\ngx-tmp-bug-repo.umd.js:411:29)
    at Function.TransformType.newTransform (C:\Users\joelw\eclipse-workspace\tow
er-poi\packages\ngx-tmp\dist\ngx-tmp\bug-repo\bundles\ngx-tmp-bug-repo.umd.js:41
6:19)

Not sure if it helps much but it is something new. Here's some context around line 411

var TransformType = /** @class */ (function (_super) {
    __extends(TransformType, _super);
    function TransformType() {
        var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
        _this.options = {};
        return _this;
    }

from ng-universal.

rat-matheson avatar rat-matheson commented on April 28, 2024

I made a bit of progress. It seems nestjs was including the umd build from angular package. When I explicitly set the only build to be the esm2015 build in the package.json, nestjs was able to properly load the package at runtime.

//Went from this
{
  "name": "@ngx-tmp/bug-repo",
  "version": "0.0.1",
  "license": "UNLICENSED",
  "peerDependencies": {
    "@mikro-orm/core": "^5.1.3"
  },
  "dependencies": {
    "tslib": "^2.3.0"
  },
  "main": "bundles/ngx-tmp-bug-repo.umd.js",
  "module": "fesm2015/ngx-tmp-bug-repo.js",
  "es2015": "fesm2015/ngx-tmp-bug-repo.js",
  "esm2015": "esm2015/ngx-tmp-bug-repo.js",
  "fesm2015": "fesm2015/ngx-tmp-bug-repo.js",
  "typings": "ngx-tmp-bug-repo.d.ts",
  "sideEffects": false
}

// to this where I updated "main" to point to esm2015
{
  "name": "@ngx-tmp/bug-repo",
  "version": "0.0.1",
  "license": "UNLICENSED",
  "peerDependencies": {
    "@mikro-orm/core": "^5.1.3"
  },
  "dependencies": {
    "tslib": "^2.3.0"
  },
  "main": "esm2015/ngx-tmp-bug-repo.js",
  "module": "fesm2015/ngx-tmp-bug-repo.js",
  "es2015": "fesm2015/ngx-tmp-bug-repo.js",
  "esm2015": "esm2015/ngx-tmp-bug-repo.js",
  "fesm2015": "fesm2015/ngx-tmp-bug-repo.js",
  "typings": "ngx-tmp-bug-repo.d.ts",
  "sideEffects": false
}

Is there a way to somehow tell nestjs which target build to use in the package.json rather than having to manually update items in the node_modules folder?

from ng-universal.

jmcdo29 avatar jmcdo29 commented on April 28, 2024

That generally should be something that typescript is determining, and how node is running, not anything specific to Nest

from ng-universal.

rat-matheson avatar rat-matheson commented on April 28, 2024

Yes, now that I've gone a bit deeper, I can see that you are right. Two possible solutions are:

  1. figuring out some way for angular to get angular to set "main" to the esm2015 build in the package.json
  2. figuring out some way to get nest to use the "esm2015" build instead of "main" from the package.json

For (1), I've looked and I don't see any easy way to do it. I probably have to create a post build script. Do you have any ideas on how to do (2)?

Feel free to close this issue if you have no ideas where to go from here. I was hoping you might know something about the nest build process such that I can either override the module import target or possible set which angular target to use.

from ng-universal.

kamilmysliwiec avatar kamilmysliwiec commented on April 28, 2024

#842 (comment)

from ng-universal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.