Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Angular build says it cannot resolve '@angular/localize/init'

ErrorModule not found: Error: Can't resolve '@angular/localize/init'

Short answer

The build imports @angular/localize, and that package is not in node_modules. Either it was never added to the project, or it is a devDependency and your Docker or CI install skipped dev packages. Add it with ng add, or install with dev dependencies for the build step.

  • Applies to Angular 20, Angular 21, Node.js 22, npm 10
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check whether the package is declared, and where.

    grep -n "@angular/localize" package.json
    ls node_modules/@angular/localize/package.json
  2. 2Match what you see, then jump to its fix

    1. 1grep prints nothing, and the import of '@angular/localize/init' or a $localize call is in your code or a library you addedThe package was never added to the projectFix
    2. 2Works on your machine, fails in a Docker build or CI where npm ci --omit=dev or NODE_ENV=production is setIt is a devDependency and the production install left it outFix

What does the error look like?

  • Module not found: Error: Can't resolve '@angular/localize/init'
  • Can't resolve '@angular/localize/init' in '/usr/src/app/src'

Cause 1 of 2

The package was never added to the project

1Check

Search the source for the import or for tagged $localize strings.

grep -rn "localize" src/ | head

2Fix

Add it with the CLI. The schematic updates package.json and the TypeScript config files, and puts a type reference at the top of main.ts.

ng add @angular/localize

3Verify

The package is listed, and the build gets past the import.

npm ls @angular/localize
npx ng build

Confirmed by angular.dev

Did this fix it?

Cause 2 of 2

It is a devDependency and the production install left it out

1Check

ng add saves the package in devDependencies by default. npm leaves devDependencies out when omit=dev or when NODE_ENV is production.

grep -n -B1 -A1 "@angular/localize" package.json
grep -n -E "omit|NODE_ENV|production" Dockerfile

2Fix

Run the Angular build in a stage that installs dev dependencies, and copy only the built output into the final image. If the app needs $localize at runtime, add the package with the runtime option so it lands in dependencies.

# build stage: dev dependencies installed
RUN npm ci
RUN npx ng build

# or, when $localize is needed at runtime
ng add @angular/localize --use-at-runtime

3Verify

Rebuild the image and confirm the build step no longer reports the module.

docker build --progress=plain .

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Build Angular in a stage that installs all dependencies, and ship only the output.
  • Run ng add for Angular packages so config and types are set in one step.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.