How to fix "Error: Module build failed: Error: Cannot find module '@angular/localize/src/tools/src/extract/extraction'" in Angular?

How to fix "Error: Module build failed: Error: Cannot find module '@angular/localize/src/tools/src/extract/extraction'" in Angular?

我尝试测试 https://angular.io/guide/i18n#localizing-your-app 中描述的 i18n 功能,但我无法 运行 i18n 提取器,因为找不到它。

我正在使用:

我想在这里添加一个示例项目,但由于公司网络限制,我无法将其推送到GitHub...所以,我所做的是:

  1. 运行 ng new ng-i18n-test
  2. 运行 cd ng-i18n-test
  3. 运行 ng add @angular/localize
  4. 将app.component.html的内容替换为<p i18n>Hello World</p>
  5. 运行 ng extract-i18n

这会导致以下错误:

./src/main.ts - Error: Module build failed: Error: Cannot find module '@angular/localize/src/tools/src/extract/extraction'
Require stack:
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\build-angular\src\extract-i18n\ivy-extract-loader.js
- C:\workspace\ng-i18n-test\node_modules\webpack\lib\ProgressPlugin.js
- C:\workspace\ng-i18n-test\node_modules\webpack\lib\index.js
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\build-webpack\src\webpack\index.js
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\build-webpack\src\index.js
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\build-angular\src\extract-i18n\index.js
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\architect\node\index.js
- C:\workspace\ng-i18n-test\node_modules\@angular\cli\models\architect-command.js
- C:\workspace\ng-i18n-test\node_modules\@angular\cli\commands\extract-i18n-impl.js
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\schematics\tools\export-ref.js
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\schematics\tools\index.js
- C:\workspace\ng-i18n-test\node_modules\@angular\cli\utilities\json-schema.js
- C:\workspace\ng-i18n-test\node_modules\@angular\cli\models\command-runner.js
- C:\workspace\ng-i18n-test\node_modules\@angular\cli\lib\cli\index.js
- C:\workspace\ng-i18n-test\node_modules\@angular\cli\lib\init.js
- C:\workspace\ng-i18n-test\node_modules\@angular\cli\bin\ng
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (C:\workspace\ng-i18n-test\node_modules\@angular-devkit\build-angular\src\extract-i18n\ivy-extract-loader.js:29:22)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)

./src/polyfills.ts - Error: Module build failed (from ./node_modules/@angular-devkit/build-angular/src/extract-i18n/ivy-extract-loader.js):
Error: Cannot find module '@angular/localize/src/tools/src/extract/extraction'
Require stack:
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\build-angular\src\extract-i18n\ivy-extract-loader.js
- C:\workspace\ng-i18n-test\node_modules\loader-runner\lib\loadLoader.js
- C:\workspace\ng-i18n-test\node_modules\loader-runner\lib\LoaderRunner.js
- C:\workspace\ng-i18n-test\node_modules\webpack\lib\NormalModuleFactory.js
- C:\workspace\ng-i18n-test\node_modules\webpack\lib\Compiler.js
- C:\workspace\ng-i18n-test\node_modules\webpack\lib\ProgressPlugin.js
- C:\workspace\ng-i18n-test\node_modules\webpack\lib\index.js
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\build-webpack\src\webpack\index.js
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\build-webpack\src\index.js
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\build-angular\src\extract-i18n\index.js
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\architect\node\index.js
- C:\workspace\ng-i18n-test\node_modules\@angular\cli\models\architect-command.js
- C:\workspace\ng-i18n-test\node_modules\@angular\cli\commands\extract-i18n-impl.js
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\schematics\tools\export-ref.js
- C:\workspace\ng-i18n-test\node_modules\@angular-devkit\schematics\tools\index.js
- C:\workspace\ng-i18n-test\node_modules\@angular\cli\utilities\json-schema.js
- C:\workspace\ng-i18n-test\node_modules\@angular\cli\models\command-runner.js
- C:\workspace\ng-i18n-test\node_modules\@angular\cli\lib\cli\index.js
- C:\workspace\ng-i18n-test\node_modules\@angular\cli\lib\init.js
- C:\workspace\ng-i18n-test\node_modules\@angular\cli\bin\ng
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
    at Function.Module._load (internal/modules/cjs/loader.js:745:27)
    at Module.require (internal/modules/cjs/loader.js:961:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (C:\workspace\ng-i18n-test\node_modules\@angular-devkit\build-angular\src\extract-i18n\ivy-extract-loader.js:29:22)
    at Module._compile (internal/modules/cjs/loader.js:1072:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
    at Module.load (internal/modules/cjs/loader.js:937:32)
    at Function.Module._load (internal/modules/cjs/loader.js:778:12)
    at Module.require (internal/modules/cjs/loader.js:961:19)

坦率地说,我不确定哪里出了问题。它是写在 i18n 指南中的。出了什么问题?

它在不同的机器上工作。我想我的机器一定有问题……太好了。我会检查我的设置。

编辑 是的,这是一个糟糕的设置。不确定是什么问题。我使用上述步骤创建了一个新的,现在可以使用了。