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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngcc: packages that fail with errors causes a crash #34500

Closed
JoostK opened this issue Dec 19, 2019 · 17 comments
Closed

ngcc: packages that fail with errors causes a crash #34500

JoostK opened this issue Dec 19, 2019 · 17 comments

Comments

@JoostK
Copy link
Member

JoostK commented Dec 19, 2019

馃悶 bug report

Affected Package

The issue is caused by package @angular/compiler-cli

Is this a regression?

Yes, the previous version in which this bug was not present was: 9.0.0-rc.6

Description

When ngcc processes a package that fails to compile, a fatal error that crashes the compiler occurs.

馃敩 Minimal Reproduction

For example angular-tree-component fails to compile:
https://app.circleci.com/jobs/github/angular/ngcc-validation/2459/parallel-runs/1?filterBy=ALL

馃敟 Exception or Error


ERROR in Cannot read property 'injectorImports' of undefined

馃實 Your Environment

Angular Version:


Angular: 9.0.0-rc.7

Anything else relevant?
n/a

@ngbot ngbot bot added this to the needsTriage milestone Dec 19, 2019
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Dec 19, 2019
@exequiel09
Copy link

Experienced the same:

Screen Shot 2019-12-20 at 8 42 50 AM

@NicolasKritter
Copy link

NicolasKritter commented Dec 20, 2019

Same error, after some investigation the error seems to be from this file :
node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\ng_module.js

at the beginning of the function NgModuleDecoratorHandler.prototype.compile = function (node, analysis, resolution)
at line 347

var ngInjectorDef = compiler_1.compileInjector(tslib_1.__assign(tslib_1.__assign({}, analysis.inj), { imports: tslib_1.__spread(analysis.inj.imports, resolution.injectorImports) }));

The problem is that the variable resolution is undefined
I added this line just before,
if(!resolution){ resolution = {injectorImports:[]}; console.log('no Injector') }
the error is gone but I end up with other error later with a dependendy that is not compatible with ivy (had problem with this before) so I can't tell if this really fix the issue or not but might be worth a try

@agustinvinao
Copy link

Trying to compile with bazel, same error for another module:

Error: Error on worker #4: TypeError: Cannot read property 'injectorImports' of undefined
    at NgModuleDecoratorHandler.compile (/Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/@angular/compiler-cli/src/ngtsc/annotations/src/ng_module.js:347:174)
    at _loop_1 (/Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/@angular/compiler-cli/ngcc/src/analysis/decoration_analyzer.js:205:38)
    at DecorationAnalyzer.compileClass (/Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/@angular/compiler-cli/ngcc/src/analysis/decoration_analyzer.js:220:21)
    at /Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/@angular/compiler-cli/ngcc/src/analysis/decoration_analyzer.js:194:41
    at Array.map (<anonymous>)
    at DecorationAnalyzer.compileFile (/Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/@angular/compiler-cli/ngcc/src/analysis/decoration_analyzer.js:193:64)
    at /Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/@angular/compiler-cli/ngcc/src/analysis/decoration_analyzer.js:133:90
    at Array.map (<anonymous>)
    at DecorationAnalyzer.analyzeProgram (/Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/@angular/compiler-cli/ngcc/src/analysis/decoration_analyzer.js:133:47)
    at Transformer.analyzeProgram (/Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/@angular/compiler-cli/ngcc/src/packages/transformer.js:123:57)
    at ClusterMaster.onWorkerMessage (/Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/@angular/compiler-cli/ngcc/src/execution/cluster/master.js:158:27)
    at /Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/@angular/compiler-cli/ngcc/src/execution/cluster/master.js:46:95
    at ClusterMaster.<anonymous> (/Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/@angular/compiler-cli/ngcc/src/execution/cluster/master.js:238:57)
    at step (/Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/tslib/tslib.js:136:27)
    at Object.next (/Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/tslib/tslib.js:117:57)
    at /Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/tslib/tslib.js:110:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/tslib/tslib.js:106:16)
    at EventEmitter.<anonymous> (/Users/agustinvinao/development/codespacelabs/bookkeeper/node_modules/@angular/compiler-cli/ngcc/src/execution/cluster/master.js:232:32)
    at EventEmitter.emit (events.js:210:5)

@grapehunter
Copy link

grapehunter commented Dec 25, 2019

The same error when running ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points
First execution error, second execution is correct

@ottodranik
Copy link

ottodranik commented Dec 25, 2019

Same problem. Tried to upgrade to "next" because ngx-echarts not compiled with ngcc 8.3.9-21 and got this error on upgrade.

@dave0688

This comment has been minimized.

@sovushka-utrom
Copy link

Same for me for Angular: 9.0.0-rc.7:
Compiling @angular/cdk/observers : es2015 as esm2015 Error: Error on worker #3: TypeError: Cannot read property 'injectorImports' of undefined at NgModuleDecoratorHandler.compile ... at EventEmitter.emit (events.js:182:13) Compiling @angular/common/http : es2015 as esm2015.

Happens on npm install that calls the recommended
"postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points".

@sovushka-utrom
Copy link

I had to remove all the node modules folder & run npm install again. Then it worked.

@gustavobmichel
Copy link

Have you guys found a way to check which package is causing the issue? I tried to looking at the logs but it doesn't seem to include the package with the problem.

@benelliott
Copy link
Contributor

@gustavobmichel My logs show the symbol that caused the issue. Can you upload yours?

@gnanakeethan
Copy link

I am using Yarn, and I tried doing a Yarn Upgrade. Then ran the Yarn Install. It worked without an issue.

@JoostK JoostK self-assigned this Jan 5, 2020
@manughub manughub modified the milestones: Backlog, v9-blockers Jan 6, 2020
JoostK added a commit to JoostK/angular that referenced this issue Jan 6, 2020
In angular#34288, ngtsc was refactored to separate the result of the analysis
and resolve phase for more granular incremental rebuilds. In this model,
any errors in one phase transition the trait into an error state, which
prevents it from being ran through subsequent phases. The ngcc compiler
on the other hand did not adopt this strict error model, which would
cause incomplete metadata鈥攄ue to errors in earlier phases鈥攖o be offered
for compilation that could result in a hard crash.

This commit changes ngcc so that it starts using ngtsc's `Trait` concept
to track transitions between the analysis, resolve and compile phase
much more explicitly. This approach makes it illegal to attempt the
compile phase when either analysis or resolve has produced errors,
avoiding the crash.

Fixes angular#34500
Resolves FW-1788
JoostK added a commit to JoostK/angular that referenced this issue Jan 14, 2020
In angular#34288, ngtsc was refactored to separate the result of the analysis
and resolve phase for more granular incremental rebuilds. In this model,
any errors in one phase transition the trait into an error state, which
prevents it from being ran through subsequent phases. The ngcc compiler
on the other hand did not adopt this strict error model, which would
cause incomplete metadata鈥攄ue to errors in earlier phases鈥攖o be offered
for compilation that could result in a hard crash.

This commit changes ngcc so that it starts using ngtsc's `Trait` concept
to track transitions between the analysis, resolve and compile phase
much more explicitly. This approach makes it illegal to attempt the
compile phase when either analysis or resolve has produced errors,
avoiding the crash.

Fixes angular#34500
Resolves FW-1788
@vokeit-gschuster
Copy link

Just FYI, when using the nightly build the bug is fixed.
Simply download @angular/compiler-cli-builds (https://github.com/angular/compiler-cli-builds) and replace it in node_modules.

@JoostK
Copy link
Member Author

JoostK commented Jan 15, 2020

@vokeit-gschuster The bug itself has not been fixed, the fix PR is still pending. However, it may be that a bug which was causing the library to fail compiling has been fixed, in which case you won't observe the bug anymore.

@vokeit-gschuster
Copy link

In my case, ngcc failed with the above given message on @angular/http/testing when only running it on node_modules ("ngcc" in the workspace root).

@wuboy0307
Copy link

In my case, ngcc failed with the above given message on angular-tree-component when compile to esm5

Compiling angular-tree-component : module as esm5
Error: Error on worker #3: TypeError: Cannot read property 'injectorImports' of undefined

JoostK added a commit to JoostK/angular that referenced this issue Jan 21, 2020
In angular#34288, ngtsc was refactored to separate the result of the analysis
and resolve phase for more granular incremental rebuilds. In this model,
any errors in one phase transition the trait into an error state, which
prevents it from being ran through subsequent phases. The ngcc compiler
on the other hand did not adopt this strict error model, which would
cause incomplete metadata鈥攄ue to errors in earlier phases鈥攖o be offered
for compilation that could result in a hard crash.

This commit changes ngcc so that it starts using ngtsc's `Trait` concept
to track transitions between the analysis, resolve and compile phase
much more explicitly. This approach makes it illegal to attempt the
compile phase when either analysis or resolve has produced errors,
avoiding the crash.

Fixes angular#34500
Resolves FW-1788
JoostK added a commit to JoostK/angular that referenced this issue Jan 21, 2020
In angular#34288, ngtsc was refactored to separate the result of the analysis
and resolve phase for more granular incremental rebuilds. In this model,
any errors in one phase transition the trait into an error state, which
prevents it from being ran through subsequent phases. The ngcc compiler
on the other hand did not adopt this strict error model, which would
cause incomplete metadata鈥攄ue to errors in earlier phases鈥攖o be offered
for compilation that could result in a hard crash.

This commit updates ngcc to take advantage of ngtsc's `TraitCompiler`,
that internally manages all Ivy classes that are part of the
compilation. This effectively replaces ngcc's own `AnalyzedFile` and
`AnalyzedClass` types, together with all of the logic to drive the
`DecoratorHandler`s. All of this is now handled in the `TraitCompiler`,
benefiting from its explicit state transitions of `Trait`s so that the
ngcc crash is a thing of the past.

Fixes angular#34500
Resolves FW-1788
@kaito3desuyo
Copy link

Exact same error on 9.0.0-rc.10.

0% compiling
Compiling <my-angular-component-library> : es2015 as esm2015

ERROR in Cannot read property 'injectorImports' of undefined

JoostK added a commit to JoostK/angular that referenced this issue Jan 23, 2020
In angular#34288, ngtsc was refactored to separate the result of the analysis
and resolve phase for more granular incremental rebuilds. In this model,
any errors in one phase transition the trait into an error state, which
prevents it from being ran through subsequent phases. The ngcc compiler
on the other hand did not adopt this strict error model, which would
cause incomplete metadata鈥攄ue to errors in earlier phases鈥攖o be offered
for compilation that could result in a hard crash.

This commit updates ngcc to take advantage of ngtsc's `TraitCompiler`,
that internally manages all Ivy classes that are part of the
compilation. This effectively replaces ngcc's own `AnalyzedFile` and
`AnalyzedClass` types, together with all of the logic to drive the
`DecoratorHandler`s. All of this is now handled in the `TraitCompiler`,
benefiting from its explicit state transitions of `Trait`s so that the
ngcc crash is a thing of the past.

Fixes angular#34500
Resolves FW-1788
AndrewKushnir pushed a commit that referenced this issue Jan 23, 2020
In #34288, ngtsc was refactored to separate the result of the analysis
and resolve phase for more granular incremental rebuilds. In this model,
any errors in one phase transition the trait into an error state, which
prevents it from being ran through subsequent phases. The ngcc compiler
on the other hand did not adopt this strict error model, which would
cause incomplete metadata鈥攄ue to errors in earlier phases鈥攖o be offered
for compilation that could result in a hard crash.

This commit updates ngcc to take advantage of ngtsc's `TraitCompiler`,
that internally manages all Ivy classes that are part of the
compilation. This effectively replaces ngcc's own `AnalyzedFile` and
`AnalyzedClass` types, together with all of the logic to drive the
`DecoratorHandler`s. All of this is now handled in the `TraitCompiler`,
benefiting from its explicit state transitions of `Trait`s so that the
ngcc crash is a thing of the past.

Fixes #34500
Resolves FW-1788

PR Close #34889
sonukapoor pushed a commit to sonukapoor/angular that referenced this issue Feb 13, 2020
)

In angular#34288, ngtsc was refactored to separate the result of the analysis
and resolve phase for more granular incremental rebuilds. In this model,
any errors in one phase transition the trait into an error state, which
prevents it from being ran through subsequent phases. The ngcc compiler
on the other hand did not adopt this strict error model, which would
cause incomplete metadata鈥攄ue to errors in earlier phases鈥攖o be offered
for compilation that could result in a hard crash.

This commit updates ngcc to take advantage of ngtsc's `TraitCompiler`,
that internally manages all Ivy classes that are part of the
compilation. This effectively replaces ngcc's own `AnalyzedFile` and
`AnalyzedClass` types, together with all of the logic to drive the
`DecoratorHandler`s. All of this is now handled in the `TraitCompiler`,
benefiting from its explicit state transitions of `Trait`s so that the
ngcc crash is a thing of the past.

Fixes angular#34500
Resolves FW-1788

PR Close angular#34889
@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 Feb 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.