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

TypeError: Cannot read property 'text' of undefined - Error: NGCC failed. #44019

Closed
4 of 15 tasks
dabbabi opened this issue Nov 2, 2021 · 19 comments
Closed
4 of 15 tasks
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: has PR
Milestone

Comments

@dabbabi
Copy link

dabbabi commented Nov 2, 2021

🐞 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.10

Description

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), :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), :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

@alan-agius4 alan-agius4 transferred this issue from angular/angular-cli Nov 2, 2021
@ngbot ngbot bot added this to the needsTriage milestone Nov 2, 2021
@gkalpak
Copy link
Member

gkalpak commented Nov 2, 2021

That is probably the issue #43938 is going to fix (but I'd have to take a more thorough look to confirm).

@gkalpak
Copy link
Member

gkalpak commented Nov 3, 2021

Actually, after looking into it a bit more, this turns out to be a different issue:

  • The error that is printed out originates from this line of the getRequiredModulePath() helper (so, it's an error caused while we are trying to throw a different error).
  • The error is caused by the fact that wrapperFn.body.getText() throws.
  • Internally, getText() tries to retrieve the ts.SourceFile of the corresponding node (here wrapperFn.body) and extract the text corresponding to the node.
  • In order to retrieve the ts.SourceFile, TypeScript traverses through the node's ancestors until it find a ts.SourceFile node (or until there is no parent):
  • In this case, retrieving the ts.SourceFile fails (i.e. return undefined), because wrapperFn.body.parent is not defined.
  • The reason .parent is not defined is that we create the source file with the setParentNodes argument set to false (i.e. tell TypeScript not to set parent nodes).
  • Once we fix this issue, we get to see the actual error that we were trying to print originally.
  • The actual problem is that wrapperFn.body.statements[0] is not an expression statement.
  • Typically, we expect the first (and only) statement of the UMD wrapper function body to be in the following form:
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('...'), ...) :
    typeof define === 'function' && define.amd ? define(['exports', '...', ...], factory) :
    (factory((global['...'] = {}), ...));
  • However, here, the UMD bundle of ng2-select@2.0.0 (which is the package that causes the error) looks like this:
    (function webpackUniversalModuleDefinition(root, factory) {
      if(typeof exports === 'object' && typeof module === 'object')
        module.exports = factory(...);
      else if(typeof define === 'function' && define.amd)
        define([...], factory);
      else if(typeof exports === 'object')
        exports["..."] = factory(...);
      else
        root["..."] = factory(...);
    })(...);

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.

gkalpak added a commit to gkalpak/angular that referenced this issue Nov 8, 2021
@gkalpak gkalpak self-assigned this Nov 8, 2021
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 9, 2021
@aarmora
Copy link

aarmora commented Nov 17, 2021

I have this issue currently. Is there a workaround in the meantime?

@blyndcide
Copy link

blyndcide commented Nov 19, 2021

Apparently this has been a breaking change since patch release v12.2.11. Currently trying to upgrade to v13. How do we find which libraries in our project Angular is now incompatible with?

@dabbabi
Copy link
Author

dabbabi commented Nov 19, 2021

Same issue for Angular 13.0.3


Angular CLI: 13.0.3
Node: 16.13.0
Package Manager: npm 8.1.4
OS: win32 x64

Angular: 13.0.2
... animations, cdk, 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.1300.3
@angular-devkit/build-angular     13.0.3
@angular-devkit/build-optimizer   0.1300.3
@angular-devkit/core              13.0.3
@angular-devkit/schematics        13.0.3
@angular/cli                      13.0.3
@nguniversal/aspnetcore-engine    13.0.1
@nguniversal/express-engine       13.0.1
@schematics/angular               13.0.3
ng-packagr                        13.0.6
rxjs                              6.6.7
typescript                        4.4.4

@Powback
Copy link

Powback commented Nov 19, 2021

I have the same issue after trying to upgrade.

    "@angular/animations": "~13.0.2",
    "@angular/cdk": "^13.0.2",
    "@angular/common": "~13.0.2",
    "@angular/compiler": "~13.0.2",
    "@angular/core": "~13.0.2",
    "@angular/forms": "~13.0.2",
    "@angular/material": "^13.0.2",
    "@angular/platform-browser": "~13.0.2",
    "@angular/platform-browser-dynamic": "~13.0.2",
    "@angular/router": "~13.0.2",
    "@angular-devkit/build-angular": "13.0.3",
    "@angular-eslint/builder": "13.0.1",
    "@angular-eslint/eslint-plugin": "13.0.1",
    "@angular-eslint/eslint-plugin-template": "13.0.1",
    "@angular-eslint/schematics": "13.0.1",
    "@angular-eslint/template-parser": "13.0.1",
    "@angular/cli": "13.0.3",
    "@angular/compiler-cli": "~13.0.2",
    "ts-node": "10.4.0",
    "typescript": "4.5.2"
Generating browser application bundles (phase: setup)...TypeError: Cannot read property 'text' of undefined
    at NodeObject.getText (C:\Users\bak\Documents\Projects\Places\Frontend\node_modules\typescript\lib\typescript.js:159379:31)
    at getRequiredModulePath (file:///C:/Users/bak/Documents/Projects/Places/Frontend/node_modules/@angular/compiler-cli/bundles/ngcc/main-ngcc.js:3523:91)
    at getImportsOfUmdModule (file:///C:/Users/bak/Documents/Projects/Places/Frontend/node_modules/@angular/compiler-cli/bundles/ngcc/main-ngcc.js:3515:13)
    at UmdDependencyHost.extractImports (file:///C:/Users/bak/Documents/Projects/Places/Frontend/node_modules/@angular/compiler-cli/bundles/ngcc/main-ngcc.js:3992:37)
    at UmdDependencyHost.recursivelyCollectDependencies (file:///C:/Users/bak/Documents/Projects/Places/Frontend/node_modules/@angular/compiler-cli/bundles/ngcc/main-ngcc.js:1471:26)
    at UmdDependencyHost.collectDependencies (file:///C:/Users/bak/Documents/Projects/Places/Frontend/node_modules/@angular/compiler-cli/bundles/ngcc/main-ngcc.js:1457:12)
    at DependencyResolver.getEntryPointWithDependencies (file:///C:/Users/bak/Documents/Projects/Places/Frontend/node_modules/@angular/compiler-cli/bundles/ngcc/main-ngcc.js:3740:12)
    at EntryPointCollector.walkDirectoryForPackages (file:///C:/Users/bak/Documents/Projects/Places/Frontend/node_modules/@angular/compiler-cli/bundles/ngcc/main-ngcc.js:4310:40)
    at EntryPointCollector.walkDirectoryForPackages (file:///C:/Users/bak/Documents/Projects/Places/Frontend/node_modules/@angular/compiler-cli/bundles/ngcc/main-ngcc.js:4330:32)
    at file:///C:/Users/bak/Documents/Projects/Places/Frontend/node_modules/@angular/compiler-cli/bundles/ngcc/main-ngcc.js:4464:70
(node:15196) UnhandledPromiseRejectionWarning: Error: NGCC failed.
    at NgccProcessor.process (C:\Users\bak\Documents\Projects\Places\Frontend\node_modules\@ngtools\webpack\src\ngcc_processor.js:146:19)
    at C:\Users\bak\Documents\Projects\Places\Frontend\node_modules\@ngtools\webpack\src\ivy\plugin.js:141:27
    at Hook.eval [as call] (eval at create (C:\Users\bak\Documents\Projects\Places\Frontend\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:20:1)
    at Hook.CALL_DELEGATE [as _call] (C:\Users\bak\Documents\Projects\Places\Frontend\node_modules\tapable\lib\Hook.js:14:14)
    at Compiler.newCompilation (C:\Users\bak\Documents\Projects\Places\Frontend\node_modules\webpack\lib\Compiler.js:1054:30)
    at C:\Users\bak\Documents\Projects\Places\Frontend\node_modules\webpack\lib\Compiler.js:1099:29
    at eval (eval at create (C:\Users\bak\Documents\Projects\Places\Frontend\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:31:1)

gkalpak added a commit to gkalpak/angular that referenced this issue Nov 20, 2021
Previously, ngcc could only handle UMD modules whose wrapper function
was implemented as a `ts.ConditionalExpression` (i.e. using a ternary
operator). This is the format emitted by popular bundlers, such as
Rollup.

This commit adds support for a different format, that uses `if/else`
statements, which is what is [emitted by Webpack][1].

[1]: https://webpack.js.org/configuration/output/#type-umd

Fixes angular#44019
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 21, 2021
Previously, ngcc could only handle UMD modules whose wrapper function
was implemented as a `ts.ConditionalExpression` (i.e. using a ternary
operator). This is the format emitted by popular bundlers, such as
Rollup.

This commit adds support for a different format, that uses `if/else`
statements, which is what is [emitted by Webpack][1].

[1]: https://webpack.js.org/configuration/output/#type-umd

Fixes angular#44019
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 21, 2021
Previously, ngcc could only handle UMD modules whose wrapper function
was implemented as a `ts.ConditionalExpression` (i.e. using a ternary
operator). This is the format emitted by popular bundlers, such as
Rollup.

This commit adds support for a different format, that uses `if/else`
statements, which is what is [emitted by Webpack][1].

[1]: https://webpack.js.org/configuration/output/#type-umd

Fixes angular#44019
@albert-asin
Copy link

Hi
Same issue with for Angular 13.0.2

cheers

gkalpak added a commit to gkalpak/angular that referenced this issue Nov 22, 2021
Previously, ngcc could only handle UMD modules whose wrapper function
was implemented as a `ts.ConditionalExpression` (i.e. using a ternary
operator). This is the format emitted by popular bundlers, such as
Rollup.

This commit adds support for a different format, that uses `if/else`
statements, which is what is [emitted by Webpack][1].

[1]: https://webpack.js.org/configuration/output/#type-umd

Fixes angular#44019
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 22, 2021
… module

Previously, the ngcc `UmdReflectionHost` would throw a misleading error
when trying to collect dependencies of an invalidly formatted UMD
module. This happened because an error would be thrown while trying to
construct the error message for the actual error, by calling `getText()`
on certain TypeScript AST nodes. See
angular#44019 (comment)
for a more in-depth explanation.

This commit ensures `getText()` can be safely called on TypeScript AST
nodes when collecting dependencies of UMD modules.
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 22, 2021
Previously, ngcc could only handle UMD modules whose wrapper function
was implemented as a `ts.ConditionalExpression` (i.e. using a ternary
operator). This is the format emitted by popular bundlers, such as
Rollup.

This commit adds support for a different format, that uses `if/else`
statements, which is what is [emitted by Webpack][1].

[1]: https://webpack.js.org/configuration/output/#type-umd

Fixes angular#44019
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 22, 2021
… module

Previously, the ngcc `UmdReflectionHost` would throw a misleading error
when trying to collect dependencies of an invalidly formatted UMD
module. This happened because an error would be thrown while trying to
construct the error message for the actual error, by calling `getText()`
on certain TypeScript AST nodes. See
angular#44019 (comment)
for a more in-depth explanation.

This commit ensures `getText()` can be safely called on TypeScript AST
nodes when collecting dependencies of UMD modules.
@gkalpak
Copy link
Member

gkalpak commented Nov 22, 2021

#44245 should fix this.

It would be great if you could grab the build artifacts from that PR (as described here) and use them with your projects to see if the problem does indeed go away 🙏

gkalpak added a commit to gkalpak/angular that referenced this issue Nov 24, 2021
Previously, ngcc could only handle UMD modules whose wrapper function
was implemented as a `ts.ConditionalExpression` (i.e. using a ternary
operator). This is the format emitted by popular bundlers, such as
Rollup.

This commit adds support for a different format, that uses `if/else`
statements, which is what is [emitted by Webpack][1].

[1]: https://webpack.js.org/configuration/output/#type-umd

Fixes angular#44019
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 24, 2021
… module

Previously, the ngcc `UmdReflectionHost` would throw a misleading error
when trying to collect dependencies of an invalidly formatted UMD
module. This happened because an error would be thrown while trying to
construct the error message for the actual error, by calling `getText()`
on certain TypeScript AST nodes. See
angular#44019 (comment)
for a more in-depth explanation.

This commit ensures `getText()` can be safely called on TypeScript AST
nodes when collecting dependencies of UMD modules.
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 24, 2021
Previously, ngcc could only handle UMD modules whose wrapper function
was implemented as a `ts.ConditionalExpression` (i.e. using a ternary
operator). This is the format emitted by popular bundlers, such as
Rollup.

This commit adds support for a different format, that uses `if/else`
statements, which is what is [emitted by Webpack][1].

[1]: https://webpack.js.org/configuration/output/#type-umd

Fixes angular#44019
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 24, 2021
… module

Previously, the ngcc `UmdReflectionHost` would throw a misleading error
when trying to collect dependencies of an invalidly formatted UMD
module. This happened because an error would be thrown while trying to
construct the error message for the actual error, by calling `getText()`
on certain TypeScript AST nodes. See
angular#44019 (comment)
for a more in-depth explanation.

This commit ensures `getText()` can be safely called on TypeScript AST
nodes when collecting dependencies of UMD modules.
@JoostK JoostK added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: has PR labels Nov 24, 2021
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Nov 24, 2021
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 26, 2021
Previously, ngcc could only handle UMD modules whose wrapper function
was implemented as a `ts.ConditionalExpression` (i.e. using a ternary
operator). This is the format emitted by popular bundlers, such as
Rollup.

This commit adds support for a different format, that uses `if/else`
statements, which is what is [emitted by Webpack][1].

[1]: https://webpack.js.org/configuration/output/#type-umd

Fixes angular#44019
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 26, 2021
… module

Previously, the ngcc `UmdReflectionHost` would throw a misleading error
when trying to collect dependencies of an invalidly formatted UMD
module. This happened because an error would be thrown while trying to
construct the error message for the actual error, by calling `getText()`
on certain TypeScript AST nodes. See
angular#44019 (comment)
for a more in-depth explanation.

This commit ensures `getText()` can be safely called on TypeScript AST
nodes when collecting dependencies of UMD modules.
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 26, 2021
… module

Previously, the ngcc `UmdReflectionHost` would throw a misleading error
when trying to collect dependencies of an invalidly formatted UMD
module. This happened because an error would be thrown while trying to
construct the error message for the actual error, by calling `getText()`
on certain TypeScript AST nodes. See
angular#44019 (comment)
for a more in-depth explanation.

This commit ensures `getText()` can be safely called on TypeScript AST
nodes when collecting dependencies of UMD modules.
@PraveenFrancis
Copy link

🐞 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.10

Description

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), :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), :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

Hi is this issue fixed . I am also getting this issue while migrating From Angular 6 to 12 . Is there any work around for this?. Can anyone help me to fix this issue ?

@gkalpak
Copy link
Member

gkalpak commented Nov 27, 2021

@PraveenFrancis
Copy link

@PraveenFrancis: #44019 (comment)

so i need to add this in package.json file ?
"dependencies": {
"@angular/common": "https://<...>.circle-artifacts.com/0/angular/common-pr12345-a1b2c3d.tgz",
"@angular/core": "https://<...>.circle-artifacts.com/0/angular/core-pr12345-a1b2c3d.tgz",
"...": "..."
}
but when i did the npm i it . I got this error => Only absolute URLs are supported
so can you help me to find the absolute urls for this?

@gkalpak
Copy link
Member

gkalpak commented Nov 27, 2021

If you want to try the fix (until it is officially released, probably next week), you can use the URLs from the PR build artifacts in our package.json. But you have to use the actual URLs for this specific PR (not the example ones shown in the docs).

So, in this case it would be:

{
  "dependencies": {
    "@angular/animations": "https://1089210-24195339-gh.circle-artifacts.com/0/angular/animations-pr44245-b2895b225f.tgz",
    "@angular/common": "https://1089210-24195339-gh.circle-artifacts.com/0/angular/common-pr44245-b2895b225f.tgz",
    // ...
  }
}

(Note that you need to replace the package name in the URL for each Angular framework package.)

BTW, I am not sure if the fix will be backported to v12 (it will land on v13).
Will that be a problem for you, @PraveenFrancis? Is there something stopping you from updating to v13?

@PraveenFrancis
Copy link

Thanks for the quick response . Actually my client only need the v12 version .

@nqtuyen92
Copy link

Hi! I same too! :(
Angular CLI: 13.0.3
Node: 16.13.0
Package Manager: npm 8.1.4
OS: darwin x64

Angular: 13.0.2
... cdk, compiler, compiler-cli, core

Package Version

@angular-devkit/architect 0.1300.3
@angular-devkit/build-angular 13.0.3
@angular-devkit/core 13.0.3
@angular-devkit/schematics 13.0.3
@angular/animations 13.1.0-next.2
@angular/cli 13.0.3
@angular/flex-layout 10.0.0-beta.32
@angular/forms 13.1.0-next.2
@angular/language-service 13.1.0-next.2
@angular/localize 13.1.0-next.2
@angular/material 13.1.0-next.2
@angular/material-moment-adapter 13.1.0-next.2
@angular/platform-browser 13.1.0-next.2
@angular/platform-browser-dynamic 13.1.0-next.2
@angular/platform-server 13.1.0-next.2
@angular/router 13.1.0-next.2
@schematics/angular 13.0.3
rxjs 7.4.0
typescript 4.5.2

dylhunn pushed a commit that referenced this issue Nov 29, 2021
… module (#44245)

Previously, the ngcc `UmdReflectionHost` would throw a misleading error
when trying to collect dependencies of an invalidly formatted UMD
module. This happened because an error would be thrown while trying to
construct the error message for the actual error, by calling `getText()`
on certain TypeScript AST nodes. See
#44019 (comment)
for a more in-depth explanation.

This commit ensures `getText()` can be safely called on TypeScript AST
nodes when collecting dependencies of UMD modules.

PR Close #44245
dylhunn pushed a commit that referenced this issue Nov 29, 2021
…#44245)

Previously, ngcc could only handle UMD modules whose wrapper function
was implemented as a `ts.ConditionalExpression` (i.e. using a ternary
operator). This is the format emitted by popular bundlers, such as
Rollup.

This commit adds support for a different format, that uses `if/else`
statements, which is what is [emitted by Webpack][1].

[1]: https://webpack.js.org/configuration/output/#type-umd

Fixes #44019

PR Close #44245
dylhunn pushed a commit that referenced this issue Nov 29, 2021
… module (#44245)

Previously, the ngcc `UmdReflectionHost` would throw a misleading error
when trying to collect dependencies of an invalidly formatted UMD
module. This happened because an error would be thrown while trying to
construct the error message for the actual error, by calling `getText()`
on certain TypeScript AST nodes. See
#44019 (comment)
for a more in-depth explanation.

This commit ensures `getText()` can be safely called on TypeScript AST
nodes when collecting dependencies of UMD modules.

PR Close #44245
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 30, 2021
…angular#44245)

Previously, ngcc could only handle UMD modules whose wrapper function
was implemented as a `ts.ConditionalExpression` (i.e. using a ternary
operator). This is the format emitted by popular bundlers, such as
Rollup.

This commit adds support for a different format, that uses `if/else`
statements, which is what is [emitted by Webpack][1].

[1]: https://webpack.js.org/configuration/output/#type-umd

Fixes angular#44019

PR Close angular#44245
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 30, 2021
… module (angular#44245)

Previously, the ngcc `UmdReflectionHost` would throw a misleading error
when trying to collect dependencies of an invalidly formatted UMD
module. This happened because an error would be thrown while trying to
construct the error message for the actual error, by calling `getText()`
on certain TypeScript AST nodes. See
angular#44019 (comment)
for a more in-depth explanation.

This commit ensures `getText()` can be safely called on TypeScript AST
nodes when collecting dependencies of UMD modules.

PR Close angular#44245
@gkalpak
Copy link
Member

gkalpak commented Nov 30, 2021

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

@4kparadise
Copy link

Hello @gkalpak,
I tried out the latest Angular Release 13.0.3 but unfortunately the bug persists. Also when I look into the angular master I see your fix #44245 is not included there. Does it still need some time that this fix will definitely be included?

Kind regards from Hamburg, Thomas Schefer

@gkalpak
Copy link
Member

gkalpak commented Dec 2, 2021

Thx for checking and reporting back, @4kparadise 👍
The fix has indeed landed on the 13.0.x branch (you can see the commit here: bf5f734). And I do see the fix in the 13.0.3 code.

Could you create a new issue, @4kparadise, and share a minimal reproduction? 🙏

@4kparadise
Copy link

You're right, forget to update the compiler-cli to 13.0.3 too. My fault, now it works!

dimakuba pushed a commit to dimakuba/angular that referenced this issue Dec 28, 2021
…angular#44245)

Previously, ngcc could only handle UMD modules whose wrapper function
was implemented as a `ts.ConditionalExpression` (i.e. using a ternary
operator). This is the format emitted by popular bundlers, such as
Rollup.

This commit adds support for a different format, that uses `if/else`
statements, which is what is [emitted by Webpack][1].

[1]: https://webpack.js.org/configuration/output/#type-umd

Fixes angular#44019

PR Close angular#44245
dimakuba pushed a commit to dimakuba/angular that referenced this issue Dec 28, 2021
… module (angular#44245)

Previously, the ngcc `UmdReflectionHost` would throw a misleading error
when trying to collect dependencies of an invalidly formatted UMD
module. This happened because an error would be thrown while trying to
construct the error message for the actual error, by calling `getText()`
on certain TypeScript AST nodes. See
angular#44019 (comment)
for a more in-depth explanation.

This commit ensures `getText()` can be safely called on TypeScript AST
nodes when collecting dependencies of UMD modules.

PR Close angular#44245
@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 Jan 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent state: has PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.