NGCC 失败了。在 NgccProcessor.process(Angular\node_modules\@ngtools\webpack\src\ngcc_processor.js:139:19)

NGCC failed. at NgccProcessor.process ( Angular\node_modules\@ngtools\webpack\src\ngcc_processor.js:139:19)

我已将我的 Angular CLI 项目从 8 升级到 9。

这是当前的 Angular CLI 和其他软件包版本:

Angular CLI: 9.1.15
Node: 14.17.0
OS: win32 x64

Angular: 9.1.13
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.1202.1
@angular-devkit/build-angular     12.2.1
@angular-devkit/build-optimizer   0.1202.1
@angular-devkit/build-webpack     0.1202.1
@angular-devkit/core              9.1.15
@angular-devkit/schematics        9.1.15
@angular/cdk                      8.2.3
@angular/cli                      9.1.15
@ngtools/webpack                  12.2.1
@schematics/angular               9.1.15
@schematics/update                0.901.15
rxjs                              6.6.7
typescript                        3.8.3
webpack                           5.50.0

我在编译项目时收到下面给出的错误。

Generating browser application bundles (phase: setup)...Options:
      --version                          Show version number           [boolean]
  -s, --source                           A path (relative to the working
                                         directory) of the `node_modules` folder
                                         to process. [default: "./node_modules"]
  -p, --properties                       An array of names of properties in
                                         package.json to compile (e.g. `module`
                                         or `es2015`)
                                         Each of these properties should hold
                                         the path to a bundle-format.
                                         If provided, only the specified
                                         properties are considered for
                                         processing.
                                         If not provided, all the supported
                                         format properties (e.g. fesm2015,
                                         fesm5, es2015, esm2015, esm5, main,
                                         module) in the package.json are
                                         considered.
                                         .......
                                         .......


Unknown arguments: use-program-dependencies, useProgramDependencies
C:\Users\x\Angular\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\x\Angular\node_modules\@ngtools\webpack\src\ngcc_processor.js:139:19)
    at C:\Users\x\Angular\node_modules\@ngtools\webpack\src\ivy\plugin.js:129:27

可以指导我如何解决这个问题吗?

运行 此命令 npm i @ngtools/webpack 并在 @ 之后提及您想要的版本,与您的 Angular 版本相同。

npm i @ngtools/webpack@9.1.15

无论您使用的 Angular 是什么版本,都选择相同的版本。

Version              Downloads (Last 7 Days)             Tag
12.2.14                           101,188               v12-lts
8.3.29                             60,775               v8-lts
9.1.15                             57,568               v9-lts
7.3.10                             34,584               v7-lts

你可以在这里找到所有的包@ngtools/webpack

我对 Angular 12Node 17.4.0 也有类似的问题。我将 Node 更改为 v16.13.2,现在它工作正常。