angular: TypeError: Cannot read property 'toJSON' of undefined

I’m submitting a … (check one with “x”)

[x] bug report

Current behavior I get the following error when attempting to run the ngc ahead-of-time compiler in Angular 4.0.0-beta.7:

TypeError: Cannot read property ‘toJSON’ of undefined at TsickleCompilerHost.sourceMapGeneratorToConsumerWithFileName (node_modules\tsickle\build\src\tsickle_compiler_host.js:92:46) at TsickleCompilerHost.combineSourceMaps (node_modules\tsickle\build\src\tsickle_compiler_host.js:124:64) at TsickleCompilerHost.writeFile (node_modules\tsickle\build\src\tsickle_compiler_host.js:78:28) at Object.writeFile (node_modules\typescript\lib\typescript.js:62941:132) at Object.writeFile (node_modules\typescript\lib\typescript.js:8936:14) at printFile (node_modules\typescript\lib\typescript.js:60023:20) at emitFile (node_modules\typescript\lib\typescript.js:59979:21) at onSingleFileEmit (node_modules\typescript\lib\typescript.js:8844:13) at Object.forEachTransformedEmitFile (node_modules\typescript\lib\typescript.js:8821:21) at Object.emitFiles (node_modules\typescript\lib\typescript.js:59962:12) Compilation failed

If I set sourceMap to false in my tsconfig.json file, the compilation works again.

Expected behavior Compilation succeeds without having to disable sourcemaps.

Minimal reproduction of the problem with instructions My full tsconfig.json is as follows:

{
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": ["es2015", "dom"],
    "noImplicitAny": true
  },
  "files": [
    "app/app.module.ts",
    "app/main.ts"
  ],
  "angularCompilerOptions": {
    "genDir": "aot",
    "skipMetadataEmit" : true
  }
}

Please tell us about your environment: Windows Server 2012 R2 (equivalent to Windows 8.1)

  • Angular version: 4.0.0-beta.7

  • Language: TypeScript 2.1.6

  • Node (for AoT issues): node --version = v7.4.0

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 14
  • Comments: 21 (7 by maintainers)

Most upvoted comments

@DzmitryShylovich I’m still seeing this issue with the release of version 4.0.0 and it looks like @mdudek is as well. When I have sourceMaps set to true and mapRoot defined as “./” this is the error I am seeing:

TypeError: Cannot read property ‘toJSON’ of undefined at Object.sourceMapGeneratorToConsumer (C:.…\node_modules\tsickle\build\src\source_map_utils.js:65:42) at TsickleCompilerHost.combineSourceMaps (C:.…\node_modules\tsickle\build\src\tsickle_compiler_host.js:167:74) at TsickleCompilerHost.writeFile (C:.…\node_modules\tsickle\build\src\tsickle_compiler_host.js:111:28) at Object.writeFile (C:.…\node_modules\typescript\lib\typescript.js:64240:132) at Object.writeFile (C:.…\node_modules\typescript\lib\typescript.js:9020:14) at printSourceFileOrBundle (C:.…\node_modules\typescript\lib\typescript.js:61197:20) at emitSourceFileOrBundle (C:.…\node_modules\typescript\lib\typescript.js:61155:21) at Object.forEachEmittedFile (C:.…\node_modules\typescript\lib\typescript.js:8986:17) at Object.emitFiles (C:.…\node_modules\typescript\lib\typescript.js:61137:12) at emitWorker (C:.…\node_modules\typescript\lib\typescript.js:64294:33)

@blacksonic

I think it is important to add information about the bug:) So, the bug is only if we set sourceMap = true and mapRoot = “” <- empty in tsconfig

@theodorejb, I’m facing same issue as @pderks right now with ng4 final.

Still exists with rc.1

I’m seeing the same issue @day01 is seeing in rc.3. To successfully run the ngc (aot compiler) I have to set sourceMap to false and take mapRoot out of the tsconfig.json file.