this._nativeError is undefined when I bundle my angular 2 application

315 Views Asked by At

I am using gulp, browserify and tsify to bundle my application and I am pointing browserify to the main.ts file. That is all I am doing to bundle the app. But when I try to run the index.html file which has the bundled js file imported, I get the error: this._nativeError is undefined with a blank screen.

My tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc-e2e",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ]
  }
}

My gulp task:

gulp task

2

There are 2 best solutions below

6
On

Regarding the tsify configuration, you define:

defaultOptions = {
  ...
  tsifyOptions: {},
  ...
}

but you use:

.plugin(tsify, defaultOptions.tsifydefaultOptions)

It's unclear as to whether or not it's related to your problem, but if your tsconfig.json is not in the same directory as your package.json and is not in a parent directory, it won't be found. And as your configuration includes ../node_modules/@types, it seems likely that it's not.

To let tsify know where the tsconfig.json is, you can specify the project option:

.plugin(tsify, { project: './some-directory/tsconfig.json' })
0
On

I had the same issue and found my solution by putting a console.log inside compiler.umd.js as suggested here: https://stackoverflow.com/a/41644735/7434393

Around line 1604 in the compiler.umd.js I added a console.log to show me the message.

It is part of the set function of the Object.defineProperty(BaseError.prototype, "message" definition.

The setter is assigning the message to the _nativeError.message, but _nativeError is undefined and thus, THAT was blowing up, hiding the REAL error message.

So, I just put a console.log to spit out the message that was being passed in, and it showed me the actual error I had (a template error).

Therefore, this appears to be a bug in their code.