angular / closure-demo

MIT License
115 stars 27 forks source link

Closure compiler exception when sourceMap set to true in tsconfig.json #25

Open gregmagolan opened 6 years ago

gregmagolan commented 6 years ago

Turning on sourceMap in src/tsconfig.json results in an exception during closure compile:

java.lang.IllegalArgumentException: a source must have a name
    at com.google.javascript.jscomp.SourceFile.<init>(SourceFile.java:106)
    at com.google.javascript.jscomp.SourceFile$OnDisk.<init>(SourceFile.java:606)
    at com.google.javascript.jscomp.SourceFile$Builder.buildFromPath(SourceFile.java:508)
    at com.google.javascript.jscomp.SourceFile.fromPath(SourceFile.java:413)
    at com.google.javascript.jscomp.SourceMapResolver.getRelativePath(SourceMapResolver.java:72)
    at com.google.javascript.jscomp.Compiler.getSourceMapping(Compiler.java:3009)
    at com.google.javascript.jscomp.SourceMap.addMapping(SourceMap.java:164)
    at com.google.javascript.jscomp.CodePrinter$MappedCodePrinter.generateSourceMap(CodePrinter.java:141)
    at com.google.javascript.jscomp.CodePrinter.toSource(CodePrinter.java:904)
    at com.google.javascript.jscomp.CodePrinter.access$300(CodePrinter.java:42)
    at com.google.javascript.jscomp.CodePrinter$Builder.build(CodePrinter.java:828)
    at com.google.javascript.jscomp.Compiler.toSource(Compiler.java:2471)
    at com.google.javascript.jscomp.Compiler.access$700(Compiler.java:101)
    at com.google.javascript.jscomp.Compiler$14.call(Compiler.java:2430)
    at com.google.javascript.jscomp.Compiler$14.call(Compiler.java:2391)
    at com.google.javascript.jscomp.CompilerExecutor.runInCompilerThread(CompilerExecutor.java:128)
    at com.google.javascript.jscomp.Compiler.runInCompilerThread(Compiler.java:860)
    at com.google.javascript.jscomp.Compiler.toSource(Compiler.java:2390)
    at com.google.javascript.jscomp.Compiler$10.call(Compiler.java:2285)
    at com.google.javascript.jscomp.Compiler$10.call(Compiler.java:2267)
    at com.google.javascript.jscomp.CompilerExecutor$2.call(CompilerExecutor.java:101)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
error Command failed with exit code 254.
error Command failed with exit code 1.

I tracked this down to coming from an invalid entry in the sources array in built/src/basic.ngfactory.js.map:

{
  "version": 3,
  "file": "basic.ngfactory.js",
  "sourceRoot": "",
  "sources": [
    "../../src/basic.ngfactory.ts",
    "file:///ng://.../closure-demo/src/basic.ng.html",
    "../../"
  ],
  "names": [],
  "mappings": ";;;;;;;;;;;uDCAA,...,CAAA"
}

The value "../../" in sources ends up creating a null or empty fileName value in the SourceFile ctor which throws the exception. This seems to have been introduced with 5.0.0-rc.0. Could not reproduce with 5.0.0-beta.7. The same "../../" entry is in basic.ngfactory.js.map with 5.0.0-beta.7 but the mappings must be different as the same closure compiler does not throw an exception.

alexeagle commented 6 years ago

@chuckjaz does this look like the source map problem you've been resolving?

chuckjaz commented 6 years ago

No but it looks like a compiler bug in that we shouldn't be emitting a file without a valid name. Can you a related bug in angular/angular?

alexeagle commented 6 years ago

Also I wonder why we don't see this problem internally.

tbosch commented 6 years ago

@alexeagle internally we use inline sourcemaps.