You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Importing RouterTestingModule in spec files causes AOT/ngc compiler to fail #11276
Current behavior
If I have RouterTestingModule imported in any of my spec files, I will get the following error:
Error: parameters received {"filePath":"/Users/qdouble/Sites/MAIN_PROJECT/node_modules/@angular/common/src/location/location.d.ts","name":"Location"} which is not a StaticSymbol
Expected/desired behavior
First of all, there should be an option to make the ngc compiler ignore spec files (other than having to go back and forward in changing your tsconfig setting to ignore spec files). I'll also assume that if it's evaluating spec files, it would make the compilation slower.
Beyond fixing the RouterTestingModule bug, I think ngc should be a setting to make ngc/aot ignore spec/e2e files.
Angular version: 2.0.0-builds --- latest
Reacted by Antony Budianto, Jesse Zhang, Steve Sewell, Rene Michels, Cédric Exbrayat, Arlo Duff, choeller, Florian Kinder, Danny Blue and Mykyta Svyrydenko
getting the same error with 2 projects now with DomSanitizerImpl as well
Error: parameters received {"filePath":"/Users/steve/Projects/forks/universal/node_modules/@angular/platform-browser/src/security/dom_sanitization_service.d.ts","name":"DomSanitizerImpl"} which is not a StaticSymbol
ng serve --p 4200 -pc proxy.json -prod --aot
Error: parameters received {"filePath":"C:/dev/projects/spring-angular2-starter/shardis-ui/node_modules/@angular/common/src/location/location.d.ts","name":"Location"} which is not a StaticSymbol
at StaticReflector.parameters (C:\Users\iminar\Dev\angular\modules\@angular\compiler-cli\src\static_reflector.ts:122:13)
at CompileMetadataResolver.getDependenciesMetadata (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:14317:56)
at CompileMetadataResolver.getTypeMetadata (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:14282:28)
at C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:14425:43
at Array.forEach (native)
at CompileMetadataResolver.getProvidersMetadata (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:14405:21)
at C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:14412:43
at Array.forEach (native)
at CompileMetadataResolver.getProvidersMetadata (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:14405:21)
at CompileMetadataResolver.getNgModuleMetadata (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:14164:60)
at C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:12936:58
at Array.forEach (native)
at OfflineCompiler.analyzeModules (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\@angular\compiler\bundles\compiler.umd.js:12935:21)
at CodeGenerator.codegen (C:\Users\iminar\Dev\angular\modules\@angular\compiler-cli\src\codegen.ts:110:45)
at NgcWebpackPlugin._make (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\@ngtools\webpack\src\plugin.js:93:35)
at Compiler.<anonymous> (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\@ngtools\webpack\src\plugin.js:64:75)
at Compiler.applyPluginsParallel (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\tapable\lib\Tapable.js:156:14)
at Compiler.compile (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\webpack\lib\Compiler.js:431:7)
at Watching.<anonymous> (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\webpack\lib\Compiler.js:47:17)
at next (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\tapable\lib\Tapable.js:81:11)
at Compiler.invalidAsyncPlugin (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\webpack-dev-middleware\middleware.js:119:3)
at next (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\tapable\lib\Tapable.js:83:14)
at Compiler.<anonymous> (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\webpack\lib\CachePlugin.js:31:4)
at Compiler.applyPluginsAsync (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\tapable\lib\Tapable.js:85:13)
at Watching._go (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\webpack\lib\Compiler.js:45:16)
at Watching.<anonymous> (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\webpack\lib\Compiler.js:37:8)
at Compiler.readRecords (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\webpack\lib\Compiler.js:339:10)
at new Watching (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\webpack\lib\Compiler.js:34:16)
at Compiler.watch (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\webpack\lib\Compiler.js:176:17)
at module.exports (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\webpack-dev-middleware\middleware.js:146:27)
at new Server (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\webpack-dev-server\lib\Server.js:54:20)
at Class.run (C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\angular-cli\tasks\serve-webpack.js:50:22)
at C:\dev\projects\spring-angular2-starter\shardis-ui\node_modules\angular-cli\commands\serve.js:85:26
at process._tickCallback (internal/process/next_tick.js:103:7)
@vicb you can reproduce by cloning qdouble's starter and removing "src/**/*.spec.ts", from "exclude" in tsconfig.aot.json and running npm run ngc
if the behavior for you is the same for me and @qdouble, you should get the same error mentioned above -
Error: parameters received {"filePath":"/Users/steve/Projects/forks/angular2webpack2-starter/node_modules/@angular/common/src/location/location.d.ts","name":"Location"} which is not a StaticSymbol
@vicb I just threw the required code updated on a branch and pushed to my origin, so even easier repro case is just clone that, npm install, and npm run ngc and you should see the same error as we are
also, @vicb in case it is helpful, this issue happens when the StaticReflector gets passed an object to it's parameters or hasLifecycleHook methods that matches the StaticSymbol interface (has the proper filePath and name properties like you see in the errors above) but just happens to not be a strict instance of StaticSymbol despite being perfectly compatible of an object
if(!(typeinstanceofStaticSymbol)){thrownewError(`parameters received ${JSON.stringify(type)} which is not a StaticSymbol`);}
with
if(!(typeinstanceofStaticSymbol)&&!type.filePath&&!type.name){thrownewError(`parameters received ${JSON.stringify(type)} which is not a StaticSymbol`);}
Everything compiles and runs as expected. Obviously that solution is inelegant but was helpful to see that something is either cloning or creating static symbols not using the same StaticSymbol constructor but are perfectly compatible StaticSymbol objects
I tried poking around for the source of when this happens, and unfortunately didn't find anything obvious, but I hope this info can still be helpful!
@qdouble Is this also happening when you manually create a tsconfig-aot.json and call ngc? I also get the error for location.d.ts but only when using the CLI and calling ng build --aot. Compiling "by hand" works for me
@qdouble Ok, I found out why it works for me (though I don't really understand what's going on there). When I add the files property with only main.ts in it to the tsconfig-aot.json it works (TypeScript still compiles all files - this is what I don't understand).
@choeller: when noResolve is false (the default), TypeScript will walk the imports and references from anything in files to accumulate the sources in the program that will be type-checked and emitted. Thus it will still compile your files, but will not discover any tests in that reference graph so they are not presented to the compiler. ngc just looks at the same files that tsc does.
After poking around more, I believe the error is pretty simple
in @angular/compilerStaticSymbol is just an interface
In @angular/compiler-cliStaticSymbol is a class with the same properties (also includes one optional property members).
@angular/compiler has an isStaticSymbolexported function that the compiler-cli should use instead of checking for instanceof as there are clearly cases (e.g., perhaps through reading metadata.json files or some other interop between compiler and compiler-cli) where objects adhering to the StaticSymbol interface are not instances of the StaticSymbol class but are perfectly compatible and should be used rather than throwing errors
Activity
steve8708 commentedon Sep 30, 2016
getting the same error with 2 projects now with
DomSanitizerImplas wellkucharzyk commentedon Oct 1, 2016
Same error for me.
vicb commentedon Oct 1, 2016
Could someone please add a minimal repro case ?
steve8708 commentedon Oct 3, 2016
@vicb you can reproduce by cloning qdouble's starter and removing
"src/**/*.spec.ts",from"exclude"intsconfig.aot.jsonand runningnpm run ngcif the behavior for you is the same for me and @qdouble, you should get the same error mentioned above -
steve8708 commentedon Oct 3, 2016
@vicb I just threw the required code updated on a branch and pushed to my origin, so even easier repro case is just clone that,
npm install, andnpm run ngcand you should see the same error as we aresteve8708 commentedon Oct 3, 2016
also, @vicb in case it is helpful, this issue happens when the
StaticReflectorgets passed an object to it'sparametersorhasLifecycleHookmethods that matches theStaticSymbolinterface (has the properfilePathandnameproperties like you see in the errors above) but just happens to not be a strict instance ofStaticSymboldespite being perfectly compatible of an objectfor example, on this line if you replace
with
Everything compiles and runs as expected. Obviously that solution is inelegant but was helpful to see that something is either cloning or creating static symbols not using the same StaticSymbol constructor but are perfectly compatible StaticSymbol objects
I tried poking around for the source of when this happens, and unfortunately didn't find anything obvious, but I hope this info can still be helpful!
vicb commentedon Oct 4, 2016
/cc @chuckjaz
choeller commentedon Oct 5, 2016
@qdouble Is this also happening when you manually create a
tsconfig-aot.jsonand callngc? I also get the error for location.d.ts but only when using the CLI and callingng build --aot. Compiling "by hand" works for mechoeller commentedon Oct 5, 2016
@qdouble Ok, I found out why it works for me (though I don't really understand what's going on there). When I add the
filesproperty with only main.ts in it to thetsconfig-aot.jsonit works (TypeScript still compiles all files - this is what I don't understand).When removing the files-property the AOT-Build crashes.
qdouble commentedon Oct 6, 2016
@choeller I basically got around the issue here by making my AOT tsconfig ignore spec files
alexeagle commentedon Oct 7, 2016
@choeller: when
noResolveis false (the default), TypeScript will walk theimports andreferences from anything infilesto accumulate the sources in the program that will be type-checked and emitted. Thus it will still compile your files, but will not discover any tests in that reference graph so they are not presented to the compiler.ngcjust looks at the same files thattscdoes.steve8708 commentedon Oct 7, 2016
In case it's helpful here, looks to be same issue as #12097
steve8708 commentedon Oct 7, 2016
After poking around more, I believe the error is pretty simple
in
@angular/compilerStaticSymbolis just an interfaceIn
@angular/compiler-cliStaticSymbolis a class with the same properties (also includes one optional propertymembers).@angular/compilerhas anisStaticSymbolexported function that thecompiler-clishould use instead of checking forinstanceofas there are clearly cases (e.g., perhaps through reading metadata.json files or some other interop betweencompilerandcompiler-cli) where objects adhering to theStaticSymbolinterface are not instances of theStaticSymbolclass but are perfectly compatible and should be used rather than throwing errorsI'll open a PR for this change shortly
steve8708 commentedon Oct 7, 2016
PR to resolve this sent #12158
angular-automatic-lock-bot commentedon Sep 10, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.