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

I tried to test the i18n features described in https://angular.io/guide/i18n#localizing-your-app but I cannot run the i18n extractor because it cannot be found.

I am using:

  • node v14.17.6
  • npm v6.14.15
  • ng v12.2.5

I wanted to add an example project here, but due to corporate network restrictions I am unable to push it to GitHub… So, what I did was:

  1. run ng new ng-i18n-test
  2. run cd ng-i18n-test
  3. run ng add @angular/localize
  4. replace the contents of app.component.html with <p i18n>Hello World</p>
  5. run ng extract-i18n

That leads to the following error:

./src/main.ts - Error: Module build failed: Error: Cannot find module '@angular/localize/src/tools/src/extract/extraction'
Require stack:
- C:workspaceng-i18n-testnode_modules@angular-devkitbuild-angularsrcextract-i18nivy-extract-loader.js
- C:workspaceng-i18n-testnode_moduleswebpacklibProgressPlugin.js
- C:workspaceng-i18n-testnode_moduleswebpacklibindex.js
- C:workspaceng-i18n-testnode_modules@angular-devkitbuild-webpacksrcwebpackindex.js
- C:workspaceng-i18n-testnode_modules@angular-devkitbuild-webpacksrcindex.js
- C:workspaceng-i18n-testnode_modules@angular-devkitbuild-angularsrcextract-i18nindex.js
- C:workspaceng-i18n-testnode_modules@angular-devkitarchitectnodenode-modules-architect-host.js
- C:workspaceng-i18n-testnode_modules@angular-devkitarchitectnodeindex.js
- C:workspaceng-i18n-testnode_modules@angularclimodelsarchitect-command.js
- C:workspaceng-i18n-testnode_modules@angularclicommandsextract-i18n-impl.js
- C:workspaceng-i18n-testnode_modules@angular-devkitschematicstoolsexport-ref.js
- C:workspaceng-i18n-testnode_modules@angular-devkitschematicstoolsindex.js
- C:workspaceng-i18n-testnode_modules@angularcliutilitiesjson-schema.js
- C:workspaceng-i18n-testnode_modules@angularclimodelscommand-runner.js
- C:workspaceng-i18n-testnode_modules@angularclilibcliindex.js
- C:workspaceng-i18n-testnode_modules@angularclilibinit.js
- C:workspaceng-i18n-testnode_modules@angularclibinng
    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:workspaceng-i18n-testnode_modules@angular-devkitbuild-angularsrcextract-i18nivy-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:workspaceng-i18n-testnode_modules@angular-devkitbuild-angularsrcextract-i18nivy-extract-loader.js
- C:workspaceng-i18n-testnode_modulesloader-runnerlibloadLoader.js
- C:workspaceng-i18n-testnode_modulesloader-runnerlibLoaderRunner.js
- C:workspaceng-i18n-testnode_moduleswebpacklibNormalModuleFactory.js
- C:workspaceng-i18n-testnode_moduleswebpacklibCompiler.js
- C:workspaceng-i18n-testnode_moduleswebpacklibProgressPlugin.js
- C:workspaceng-i18n-testnode_moduleswebpacklibindex.js
- C:workspaceng-i18n-testnode_modules@angular-devkitbuild-webpacksrcwebpackindex.js
- C:workspaceng-i18n-testnode_modules@angular-devkitbuild-webpacksrcindex.js
- C:workspaceng-i18n-testnode_modules@angular-devkitbuild-angularsrcextract-i18nindex.js
- C:workspaceng-i18n-testnode_modules@angular-devkitarchitectnodenode-modules-architect-host.js
- C:workspaceng-i18n-testnode_modules@angular-devkitarchitectnodeindex.js
- C:workspaceng-i18n-testnode_modules@angularclimodelsarchitect-command.js
- C:workspaceng-i18n-testnode_modules@angularclicommandsextract-i18n-impl.js
- C:workspaceng-i18n-testnode_modules@angular-devkitschematicstoolsexport-ref.js
- C:workspaceng-i18n-testnode_modules@angular-devkitschematicstoolsindex.js
- C:workspaceng-i18n-testnode_modules@angularcliutilitiesjson-schema.js
- C:workspaceng-i18n-testnode_modules@angularclimodelscommand-runner.js
- C:workspaceng-i18n-testnode_modules@angularclilibcliindex.js
- C:workspaceng-i18n-testnode_modules@angularclilibinit.js
- C:workspaceng-i18n-testnode_modules@angularclibinng
    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:workspaceng-i18n-testnode_modules@angular-devkitbuild-angularsrcextract-i18nivy-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)

Frankly, I am not sure what went wrong. It is was is written in the i18n guide. What went wrong?

Answer

It works on a different machine. I guess there has to be an issue with my machine… Great. I’ll check my setup.

Edit yep, it was a bad setup. Not sure what the issue was. I created a new one using the steps above and it works now.