Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing RouterTestingModule in spec files causes AOT/ngc compiler to fail #11276

Closed
qdouble opened this issue Sep 2, 2016 · 15 comments · Fixed by #12158
Closed

Importing RouterTestingModule in spec files causes AOT/ngc compiler to fail #11276

qdouble opened this issue Sep 2, 2016 · 15 comments · Fixed by #12158
Labels
area: core Issues related to the framework runtime needs reproduction This issue needs a reproduction in order for the team to investigate further

Comments

@qdouble
Copy link

qdouble commented Sep 2, 2016

I'm submitting a ... (check one with "x")

[x] bug report

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
@tbosch tbosch added the area: core Issues related to the framework runtime label Sep 16, 2016
@steve8708
Copy link
Contributor

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

@kucharzyk
Copy link

Same error for me.

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
Copy link
Contributor

vicb commented Oct 1, 2016

Could someone please add a minimal repro case ?

@steve8708
Copy link
Contributor

steve8708 commented Oct 3, 2016

@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

@steve8708
Copy link
Contributor

@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

@steve8708
Copy link
Contributor

steve8708 commented Oct 3, 2016

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

for example, on this line if you replace

if (!(type instanceof StaticSymbol)) { 
    throw new Error(`parameters received ${JSON.stringify(type)} which is not a StaticSymbol`);
}

with

if (!(type instanceof StaticSymbol) && !type.filePath && !type.name) { 
    throw new Error(`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!

@vicb
Copy link
Contributor

vicb commented Oct 4, 2016

/cc @chuckjaz

@IgorMinar IgorMinar added needs reproduction This issue needs a reproduction in order for the team to investigate further and removed needs reproduction This issue needs a reproduction in order for the team to investigate further need: repro labels Oct 4, 2016
@choeller
Copy link
Contributor

choeller commented Oct 5, 2016

@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

@choeller
Copy link
Contributor

choeller commented 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 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).

{
  "compilerOptions": {
    ...
  },
  "files": [
    "main.ts"
  ],

  "angularCompilerOptions": {
    "genDir": "aot",
    "skipMetadataEmit" : true
  }
}

When removing the files-property the AOT-Build crashes.

@qdouble
Copy link
Author

qdouble commented Oct 6, 2016

@choeller I basically got around the issue here by making my AOT tsconfig ignore spec files

"exclude": [
    "node_modules",
    "src/compiled",
    "src/**/*.e2e.ts",
    "src/**/*.spec.ts",
    "src/main.browser.aot.ts"
  ],

@alexeagle
Copy link
Contributor

@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.

@steve8708
Copy link
Contributor

In case it's helpful here, looks to be same issue as #12097

@steve8708
Copy link
Contributor

After poking around more, I believe the error is pretty simple

in @angular/compiler StaticSymbol is just an interface

In @angular/compiler-cli StaticSymbol is a class with the same properties (also includes one optional property members).

@angular/compiler has an isStaticSymbol exported 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

I'll open a PR for this change shortly

@steve8708
Copy link
Contributor

PR to resolve this sent #12158

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime needs reproduction This issue needs a reproduction in order for the team to investigate further
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants