Maaz Zindani

Loading the index…

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

SyntaxError: Unexpected token '.' when running npm install or the Angular CLI

ErrorSyntaxError: 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.

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

Fix it fast

  1. 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 node
  2. 2Match what you see, then jump to its fix

    1. 1The node -v output is older than the minimum in the table for your Angular majorNode.js is outside the range the Angular version supportsFix
    2. 2node -v is right in one terminal and old in another, or in the editor's terminalNew shells start another Node.js than the one you installedFix

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 version

2Fix

Install a Node.js version from the range for your Angular major. Angular asks for an active or maintenance LTS release.

nvm install 22

3Verify

node -v prints a version inside the range and npm install runs.

node -v
npm install

Confirmed by angular.dev

Did this fix it?

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 ls

2Fix

Set the default alias, or let a .nvmrc in the project choose the version.

nvm alias default 22
echo 22 > .nvmrc
nvm use

3Verify

Open a new terminal and print the version again.

node -v

Confirmed by github.com

Did this fix it?

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 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.