SyntaxError: Unexpected token '.' when running npm install or the Angular CLI
SyntaxError: Unexpected token '.'Short answer
The tool was written for a newer Node.js than the one running it. Print node -v, compare it with the Node range your Angular version needs, and install or switch to a version inside that range. Then check that new shells use it, because a version manager may start another one.
Fix it fast
1Find out which cause you have
Print the Node.js and npm versions that this shell really runs, and where node comes from.
node -v npm -v which node2Match what you see, then jump to its fix
What does the error look like?
SyntaxError: Unexpected token '.'Unexpected token '.' when trying to run 'npm install'
Cause 1 of 2
Node.js is outside the range the Angular version supports
1Check
Angular lists the Node.js range for each major. For Angular 21 and 20 it is ^20.19.0, ^22.12.0 or ^24.0.0; for Angular 19 and 18 it is ^18.19.1, ^20.11.1 or ^22.0.0.
npx ng version2Fix
Install a Node.js version from the range for your Angular major. Angular asks for an active or maintenance LTS release.
nvm install 223Verify
node -v prints a version inside the range and npm install runs.
node -v
npm installConfirmed by angular.dev
Cause 2 of 2
New shells start another Node.js than the one you installed
1Check
nvm says the first version installed becomes the default for new shells. List what is installed and which one is active.
nvm ls2Fix
Set the default alias, or let a .nvmrc in the project choose the version.
nvm alias default 22
echo 22 > .nvmrc
nvm use3Verify
Open a new terminal and print the version again.
node -vConfirmed by github.com
How do I stop it coming back?
- Commit a .nvmrc and set the engines field so the team and CI use the same Node.js.
- Check the Angular version table before upgrading Angular or Node.js.
- Do not pin an old Node.js in CI after the project moved on.
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 fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack 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 fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix