Skip to content

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

Closed

Description

@qdouble

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

Activity

  1. steve8708 commented on Sep 30, 2016

    @steve8708
    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
    
  2. kucharzyk commented on Oct 1, 2016

    @kucharzyk

    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)
    
  3. vicb commented on Oct 1, 2016

    @vicb
    Contributor

    Could someone please add a minimal repro case ?

  4. steve8708 commented on Oct 3, 2016

    @steve8708
    Contributor

    @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
    
  5. steve8708 commented on Oct 3, 2016

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

  6. steve8708 commented on Oct 3, 2016

    @steve8708
    Contributor

    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!

  7. vicb commented on Oct 4, 2016

    @vicb
    Contributor
  8. added
    needs reproductionThis issue needs a reproduction in order for the team to investigate further
    and removed
    needs reproductionThis issue needs a reproduction in order for the team to investigate further
    on Oct 4, 2016
  9. choeller commented on Oct 5, 2016

    @choeller
    Contributor

    @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

  10. choeller commented on Oct 5, 2016

    @choeller
    Contributor

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

  11. qdouble commented on Oct 6, 2016

    @qdouble
    Author

    @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"
      ],
  12. alexeagle commented on Oct 7, 2016

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

  13. steve8708 commented on Oct 7, 2016

    @steve8708
    Contributor

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

  14. steve8708 commented on Oct 7, 2016

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

  15. steve8708 commented on Oct 7, 2016

    @steve8708
    Contributor

    PR to resolve this sent #12158

  16. angular-automatic-lock-bot commented on Sep 10, 2019

    @angular-automatic-lock-bot

    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.

  17. locked and limited conversation to collaborators on Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimeneeds reproductionThis issue needs a reproduction in order for the team to investigate further

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions