Skip to content

[6.0.0-rc.1+] NGC fails when using classes from tns-core-modules as injection tokens #23310

Closed
@sis0k0

Description

@sis0k0

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

We are using two classes (Page and Frame) from NativeScript Core (the tns-core-modules node package) as injection tokens for providers in the nativescript-angular package. After switching from @angular/compiler-rc.0 to @angular/compiler-rc.1, NGC started failing with the following error:

TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined
    at __read (/.../nativescript-angular/nativescript-angular/node_modules/tslib/tslib.js:155:50)
    at Object.__spread (/.../nativescript-angular/nativescript-angular/node_modules/tslib/tslib.js:173:28)
    at StaticReflector._annotations (/.../nativescript-angular/nativescript-angular/node_modules/@angular/compiler/src/aot/static_reflector.js:147:69)
    at StaticReflector.annotations (/.../nativescript-angular/nativescript-angular/node_modules/@angular/compiler/src/aot/static_reflector.js:123:25)
    at StaticReflector.tryAnnotations (/.../nativescript-angular/nativescript-angular/node_modules/@angular/compiler/src/aot/static_reflector.js:115:29)
    at CompileMetadataResolver.isInjectable (/.../nativescript-angular/nativescript-angular/node_modules/@angular/compiler/src/metadata_resolver.js:693:47)
    at /.../nativescript-angular/nativescript-angular/node_modules/@angular/compiler/src/aot/compiler.js:730:42
    at Array.forEach (<anonymous>)
    at analyzeFileForInjectables (/.../nativescript-angular/nativescript-angular/node_modules/@angular/compiler/src/aot/compiler.js:722:57)
    at AotCompiler._analyzeFileForInjectables (/.../nativescript-angular/nativescript-angular/node_modules/@angular/compiler/src/aot/compiler.js:90:32)

The error is thrown from here - https://github.com/angular/angular/blob/master/packages/compiler/src/aot/static_reflector.ts#L166

The difference in the generated JavaScript code for rc.0 vs rc.1:

// rc.0
annotations.push.apply(annotations, ownAnnotations_1);
// rc.1
annotations.push.apply(annotations, tslib_1.__spread(ownAnnotations_1));

The tslib spread function throws because ownAnnotations_1 is undefined.
ownAnnotations_1 is undefined for the type NativeScriptCommonModule both with rc.0 and rc.1.
Here's a simplified version of the NativeScriptCommonModule class:
https://github.com/sis0k0/ngc-6-exception/blob/master/index.ts#L5-L15

Removing that provider causes the ownAnnotations_1 array to be populated correctly and the compilation succeeds.
NGC also succeeds if we build the tns-core-modules package with NGC (which generates metadata/.ngsummary.jsons) and use that package as a dependency.

Minimal reproduction of the problem with instructions

The problem can be reproduced with this project which has a single NgModule with one of the providers that cause problems.

git clone https://github.com/sis0k0/ngc-6-exception
cd ngc-6-exception && npm i
./node_modules/.bin/ngc

Environment


Angular version: 6.0.0-rc.1, 6.0.0-rc.2
Node version: tried with 6.11.2, 8.0.0, 9.9.0
Platform: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtime

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions