closure-demo icon indicating copy to clipboard operation
closure-demo copied to clipboard

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

Open gregmagolan opened this issue 6 years ago • 4 comments

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.

gregmagolan avatar Oct 08 '17 04:10 gregmagolan

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

alexeagle avatar Oct 20 '17 14:10 alexeagle

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?

chuckjaz avatar Oct 23 '17 23:10 chuckjaz

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

alexeagle avatar Oct 27 '17 16:10 alexeagle

@alexeagle internally we use inline sourcemaps.

tbosch avatar Oct 27 '17 20:10 tbosch