angular: TypeError: Cannot read property 'text' of undefined - Error: NGCC failed.
๐ Bug report
Command (mark with an x
)
- new
- build
- serve
- test
- e2e
- generate
- add
- update
- lint
- extract-i18n
- run
- config
- help
- version
- doc
Is this a regression?
Yes, the previous version in which this bug was not present was: 12.2.10Description
After upgrading angular from version 12.2.10 to 12.2.11 or 12.2.12, I can't build anymore my project.๐ฌ Minimal Reproduction
I attached a repo-app, under the project folder, run the follwoing to reproduce the error:
npm i
ng build
๐ฅ Exception or Error
- Generating browser application bundles (phase: setup)...TypeError: Cannot read property 'text' of undefined
at NodeObject.getText (C:\Users\user\git\angular\repro-app\node_modules\typescript\lib\typescript.js:148615:31)
at getRequiredModulePath (C:\Users\user\git\angular\repro-app\node_modules\@angular\compiler-cli\ngcc\src\host\umd_host.js:519:99)
at Object.getImportsOfUmdModule (C:\Users\user\git\angular\repro-app\node_modules\@angular\compiler-cli\ngcc\src\host\umd_host.js:510:23)
at UmdDependencyHost.extractImports (C:\Users\user\git\angular\repro-app\node_modules\@angular\compiler-cli\ngcc\src\dependencies\umd_dependency_host.js:43:54)
at UmdDependencyHost.DependencyHostBase.recursivelyCollectDependencies (C:\Users\user\git\angular\repro-app\node_modules\@angular\compiler-cli\ngcc\src\dependencies\dependency_host.js:85:32)
at UmdDependencyHost.DependencyHostBase.collectDependencies (C:\Users\user\git\angular\repro-app\node_modules\@angular\compiler-cli\ngcc\src\dependencies\dependency_host.js:38:22)
at DependencyResolver.getEntryPointWithDependencies (C:\Users\user\git\angular\repro-app\node_modules\@angular\compiler-cli\ngcc\src\dependencies\dependency_resolver.js:75:22)
at EntryPointCollector.walkDirectoryForPackages (C:\Users\user\git\angular\repro-app\node_modules\@angular\compiler-cli\ngcc\src\entry_point_finder\entry_point_collector.js:47:52)
at EntryPointCollector.walkDirectoryForPackages (C:\Users\user\git\angular\repro-app\node_modules\@angular\compiler-cli\ngcc\src\entry_point_finder\entry_point_collector.js:75:103)
at C:\Users\user\git\angular\repro-app\node_modules\@angular\compiler-cli\ngcc\src\entry_point_finder\program_based_entry_point_finder.js:124:100
C:\Users\user\git\angular\repro-app\node_modules\@ngtools\webpack\src\ngcc_processor.js:139
throw new Error(errorMessage + `NGCC failed${errorMessage ? ', see above' : ''}.`);
^
Error: NGCC failed.
at NgccProcessor.process (C:\Users\user\git\angular\repro-app\node_modules\@ngtools\webpack\src\ngcc_processor.js:139:19)
at C:\Users\user\git\angular\repro-app\node_modules\@ngtools\webpack\src\ivy\plugin.js:129:27
at Hook.eval [as call] (eval at create (C:\Users\user\git\angular\repro-app\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:20:1)
at Hook.CALL_DELEGATE [as _call] (C:\Users\user\git\angular\repro-app\node_modules\tapable\lib\Hook.js:14:14)
at Compiler.newCompilation (C:\Users\user\git\angular\repro-app\node_modules\webpack\lib\Compiler.js:1043:30)
at C:\Users\user\git\angular\repro-app\node_modules\webpack\lib\Compiler.js:1088:29
at Hook.eval [as callAsync] (eval at create (C:\Users\user\git\angular\repro-app\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:22:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (C:\Users\user\git\angular\repro-app\node_modules\tapable\lib\Hook.js:18:14)
at Compiler.compile (C:\Users\user\git\angular\repro-app\node_modules\webpack\lib\Compiler.js:1083:28)
at C:\Users\user\git\angular\repro-app\node_modules\webpack\lib\Watching.js:200:19
๐ Your Environment
Angular CLI: 12.2.12
Node: 14.18.1
Package Manager: npm 6.14.15
OS: win32 x64
Angular: 12.2.12
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, google-maps, language-service, localize, material
... platform-browser, platform-browser-dynamic, platform-server
... router, service-worker
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.1200.5
@angular-devkit/build-angular 12.2.12
@angular-devkit/build-optimizer 0.1200.5
@angular-devkit/core 12.0.5
@angular-devkit/schematics 12.2.12
@nguniversal/builders 12.1.3
@nguniversal/express-engine 12.1.3
@schematics/angular 12.2.12
ng-packagr 12.2.5
rxjs 6.6.7
typescript 4.2.4
Anything else relevant?
Kindly check below a zip of an angular-cli project to reproduce the error: repro-app.zip
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 5
- Comments: 19 (7 by maintainers)
Commits related to this issue
- WIP - fix(ngcc): support more UMD formats (see #44019) — committed to gkalpak/angular by gkalpak 3 years ago
- WIP - fix(ngcc): support more UMD formats (see #44019) — committed to gkalpak/angular by gkalpak 3 years ago
- fix(ngcc): support the UMD wrapper function format emitted by Webpack Previously, ngcc could only handle UMD modules whose wrapper function was implemented as a `ts.ConditionalExpression` (i.e. using... — committed to gkalpak/angular by gkalpak 3 years ago
- fix(ngcc): support the UMD wrapper function format emitted by Webpack Previously, ngcc could only handle UMD modules whose wrapper function was implemented as a `ts.ConditionalExpression` (i.e. using... — committed to gkalpak/angular by gkalpak 3 years ago
- fix(ngcc): support the UMD wrapper function format emitted by Webpack Previously, ngcc could only handle UMD modules whose wrapper function was implemented as a `ts.ConditionalExpression` (i.e. using... — committed to gkalpak/angular by gkalpak 3 years ago
- fix(ngcc): support the UMD wrapper function format emitted by Webpack Previously, ngcc could only handle UMD modules whose wrapper function was implemented as a `ts.ConditionalExpression` (i.e. using... — committed to gkalpak/angular by gkalpak 3 years ago
- fix(ngcc): correctly report error when collecting dependencies of UMD module Previously, the ngcc `UmdReflectionHost` would throw a misleading error when trying to collect dependencies of an invalidl... — committed to gkalpak/angular by gkalpak 3 years ago
- fix(ngcc): support the UMD wrapper function format emitted by Webpack Previously, ngcc could only handle UMD modules whose wrapper function was implemented as a `ts.ConditionalExpression` (i.e. using... — committed to gkalpak/angular by gkalpak 3 years ago
- fix(ngcc): correctly report error when collecting dependencies of UMD module Previously, the ngcc `UmdReflectionHost` would throw a misleading error when trying to collect dependencies of an invalidl... — committed to gkalpak/angular by gkalpak 3 years ago
- fix(ngcc): support the UMD wrapper function format emitted by Webpack Previously, ngcc could only handle UMD modules whose wrapper function was implemented as a `ts.ConditionalExpression` (i.e. using... — committed to gkalpak/angular by gkalpak 3 years ago
- fix(ngcc): correctly report error when collecting dependencies of UMD module Previously, the ngcc `UmdReflectionHost` would throw a misleading error when trying to collect dependencies of an invalidl... — committed to gkalpak/angular by gkalpak 3 years ago
- fix(ngcc): support the UMD wrapper function format emitted by Webpack Previously, ngcc could only handle UMD modules whose wrapper function was implemented as a `ts.ConditionalExpression` (i.e. using... — committed to gkalpak/angular by gkalpak 3 years ago
- fix(ngcc): correctly report error when collecting dependencies of UMD module Previously, the ngcc `UmdReflectionHost` would throw a misleading error when trying to collect dependencies of an invalidl... — committed to gkalpak/angular by gkalpak 3 years ago
- fix(ngcc): support the UMD wrapper function format emitted by Webpack Previously, ngcc could only handle UMD modules whose wrapper function was implemented as a `ts.ConditionalExpression` (i.e. using... — committed to gkalpak/angular by gkalpak 3 years ago
- fix(ngcc): correctly report error when collecting dependencies of UMD module Previously, the ngcc `UmdReflectionHost` would throw a misleading error when trying to collect dependencies of an invalidl... — committed to gkalpak/angular by gkalpak 3 years ago
- fix(ngcc): correctly report error when collecting dependencies of UMD module Previously, the ngcc `UmdReflectionHost` would throw a misleading error when trying to collect dependencies of an invalidl... — committed to gkalpak/angular by gkalpak 3 years ago
- fix(ngcc): correctly report error when collecting dependencies of UMD module (#44245) Previously, the ngcc `UmdReflectionHost` would throw a misleading error when trying to collect dependencies of an... — committed to angular/angular by gkalpak 3 years ago
- fix(ngcc): support the UMD wrapper function format emitted by Webpack (#44245) Previously, ngcc could only handle UMD modules whose wrapper function was implemented as a `ts.ConditionalExpression` (i... — committed to angular/angular by gkalpak 3 years ago
- fix(ngcc): correctly report error when collecting dependencies of UMD module (#44245) Previously, the ngcc `UmdReflectionHost` would throw a misleading error when trying to collect dependencies of an... — committed to angular/angular by gkalpak 3 years ago
- fix(ngcc): support the UMD wrapper function format emitted by Webpack (#44245) Previously, ngcc could only handle UMD modules whose wrapper function was implemented as a `ts.ConditionalExpression` (i... — committed to gkalpak/angular by gkalpak 3 years ago
This fix has been merged and will be included in the next v13 release (13.0.3).
@PraveenFrancis, typically we wouldnโt backport this to v12 (which is an LTS version) based on our release policy, but since it was an easy/clean backport and we are releasing an LTS version to fix some other issues/regressions, I created #44309. So, the fix will eventually land to the v12 branch, but not sure when the next v12 release will be (could be in a month or so).
Youโre right, forget to update the compiler-cli to 13.0.3 too. My fault, now it works!
Thx for checking and reporting back, @4kparadise ๐ The fix has indeed landed on the 13.0.x branch (you can see the commit here: bf5f734e9c38bfcc43688410e70d741ff19b9acb). And I do see the fix in the 13.0.3 code.
Could you create a new issue, @4kparadise, and share a minimal reproduction? ๐
Actually, after looking into it a bit more, this turns out to be a different issue:
getRequiredModulePath()
helper (so, itโs an error caused while we are trying to throw a different error).wrapperFn.body.getText()
throws.getText()
tries to retrieve thets.SourceFile
of the corresponding node (herewrapperFn.body
) and extract the text corresponding to the node.ts.SourceFile
, TypeScript traverses through the nodeโs ancestors until it find ats.SourceFile
node (or until there is no parent):ts.SourceFile
fails (i.e. returnundefined
), becausewrapperFn.body.parent
is not defined..parent
is not defined is that we create the source file with thesetParentNodes
argument set tofalse
(i.e. tell TypeScript not to set parent nodes).wrapperFn.body.statements[0]
is not an expression statement.ng2-select@2.0.0
(which is the package that causes the error) looks like this:So, to fix this, we should update the
UmdHost
and associated helpers to cope with that additional UMD wrapper function body format that is emitted by Webpack.