50

I am trying to install the angular cli with 'npm install -g @angular/cli' and I am met with the following error:

npm ERR! Unexpected token '.'
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\<user>\AppData\Local\npm-cache\_logs\2022-02-02T15_25_07_320Z-debug-0.log

Version of npm: 8.3.1 Version of node: v17.4.0

Any help would be greatly appreciated! Thank you :)

Dolphin
  • 29,069
  • 61
  • 260
  • 539
Thomas Stout
  • 503
  • 1
  • 4
  • 8
  • 4
    falling back to `node 16.13.2` fixed it for me on Windows – STEEL May 24 '22 at 05:14
  • 8
    You'll also encounter this problem if you are using [`nvm-windows`](https://github.com/coreybutler/nvm-windows) prior to v1.1.8 due to how it retrieved Node.js distributions. – jacobq May 31 '22 at 17:34
  • @STEEL it is the same as me. I downgrade my node from `16.14.2` to `16.13.2`, then `npm install --global xxx` works. Thx – Orionpax Jun 28 '22 at 00:20
  • I am facing this issue with node `18.7.0` and npm `8.18.0` – Mansoor Ul Haq Aug 23 '22 at 12:02

13 Answers13

38

Had this issue on Win 10, npm 8.1.2, node 16.14.2, nvm 1.1.17 and 1.1.19. Downgrading to node 16.13.2 fixed the problem as per this answer: https://github.com/npm/cli/issues/4234#issuecomment-1025421643

Shimi Shimson
  • 990
  • 9
  • 10
35

If you are using NVM 1.1.7, you can upgrade to NVM 1.1.9

nvm Portal: https://github.com/coreybutler/nvm-windows/releases

王超华
  • 402
  • 3
  • 3
  • 5
    `choco upgrade nvm` and reinstall nodejs with `nvm` . – Jerry Sep 18 '22 at 14:33
  • 4
    Here at Windows 11, this was the simplest and correct answer at the same time. All good after manually installing NVM 1.1.9, then `nvm install 16.18.0` and `nvm use 16.18.0`. After that, using NPM global installs turned to be successful again, like `npm install -g yarn`. – Erick Petrucelli Oct 25 '22 at 17:18
  • That's the correct answer. Just updated NVM for Windows. – Konrad G Nov 11 '22 at 17:14
  • I had to reinstall the node version to make it work with the newest NVM version (1.1.10) – VRC Mar 14 '23 at 16:32
25

I had this problem with Windows 10 and Node 18 and NPM 8. I also used NVM for Windows. This is what I did to get around the problem:

  • install latest version of NVM for Windows on top of existing
  • call nvm uninstall 18.X.X, where 18.X.X is the version you are using
  • call nvm install 18.X.X, where 18.X.X is the version you are using
nbkhope
  • 7,360
  • 4
  • 40
  • 58
24

This is a reported issue for npm version 8.3.1.

Your best bet is to skip this version (Either use 8.3.2 or 8.4), use an earlier version (8.3.0) or use another node version (< 17).

Philipp Meissner
  • 5,273
  • 5
  • 34
  • 59
  • 18
    Note that if you are using [nvm for windows](https://github.com/coreybutler/nvm-windows) < 1.1.9 you might see this even with new node/npm. – jacobq Apr 25 '22 at 20:05
  • 8
    v16.13.2 worked to me. From v16.14.0 to latest (v16.15.0 for now) all use the buggy version npm version 8.3.1. – Val Apr 28 '22 at 06:15
  • @philipp-meissner yes but how do you change to an earlier vesion when `npm i -g npm@some-version` throws an error? – joniba Jun 20 '22 at 11:39
  • @joniba uninstall node and install it again. Even better: Use a version manager like nvm (https://npm.github.io/installation-setup-docs/installing/using-a-node-version-manager.html) – Philipp Meissner Jun 27 '22 at 06:40
  • 2
    I encountered the same problem too, Win10, NVM@`1.1.4`, node@[`16.15.1`, 16.15.0`,`14.10.0`], npm@`~8.3.1`. Upgrading NVM to `>=1.1.9` (as @jacobq mentioned) and reinstalling all node versions resolved the issue. – soumasandesu Jul 04 '22 at 04:51
  • FWIW, I got the same error on npm version 8.5.5 – Rick Kirkham Jul 20 '22 at 23:44
  • @jacobq's comment fixed it for me. – greduan Mar 01 '23 at 10:42
  • v16.13.1 works for me. However Angular errors out saying "The Angular CLI requires a minimum Node.js version of either v14.20, v16.14 or v18.10". These higher versions don't work! – P.Brian.Mackey Jun 07 '23 at 17:41
  • v16 is supposed to work, as stated in the answer. Given that it is quite old already, your best bet would be to update to v18.10 or above. – Philipp Meissner Jun 08 '23 at 06:58
16

The following worked for me.

Upgrade NVM for windows to version 1.1.10 by downloading the 'nvm-update.zip' folder from their repository (https://github.com/coreybutler/nvm-windows/releases) and install it.

After that remove the broken node version (in my case 18.10.0) and re-install it again using the updated NVM.

Everything working again

Telma C.
  • 356
  • 2
  • 6
5

The main problem is that, if you try to follow the steps to install angular, you will inevitably run into this error, because the recommended version of node.js is 16.14.0, and node already tells you that it comes with 8.3.1 node version: captura de pantalla de node.js con la versión recomendada de node

To solve this problem, you can install node versión 16.13.2, that comes with npm 8.1.2 version (instead of 8.1.3), as it is said here: https://nodejs.org/en/download/releases/

Note: I use nvm

Then you could install angular.

Another possibility, if you want to use angular with node 16.14.0, could be to upgrade the npm version. The problem is that, when you try to do so, it will arise the same error that appeared when you tried to install angular.

To solve this, I recommend this:

a) Install a previous version of node that uses another version of npm, as node 16.13.2, that comes with npm 8.1.2. Personally I have several versions of node through nvm (node version manager) for windows.

b) Copy the npm package of this node installation of node 16.13.2, and change it into the folder of the node 16.14.0 (delete or rename old npm folder before).

c) Use node 16.14.0 typing nvm use 16.4.0

d) Upgrade npm typing npm install -g npm@latest.

Here you could see the sequence:

First, rename npm 8.1.3 and paste npm 8.1.2: Muestra cómo quedan las carpetas con el npm

Then, you can see here the commands in the MS-DOS console:

C:\Users\AB>npm -v
    8.1.2

 
C:\Users\AB>npm version
    {
      npm: '8.1.2',
      node: '16.14.0',
      v8: '9.4.146.24-node.20',
      uv: '1.43.0',
      zlib: '1.2.11',
      brotli: '1.0.9',
      ares: '1.18.1',
      modules: '93',
      nghttp2: '1.45.1',
      napi: '8',
      llhttp: '6.0.4',
      openssl: '1.1.1m+quic',
      cldr: '40.0',
      icu: '70.1',
      tz: '2021a3',
      unicode: '14.0',
      ngtcp2: '0.1.0-DEV',
      nghttp3: '0.1.0-DEV'
    }
     

C:\Users\AB>npm install -g npm@latest
  
    removed 186 packages, changed 19 packages, and audited 36 packages in 25s
       
found 0 vulnerabilities
     

C:\Users\AB>npm version

{
      npm: '8.5.2',
      node: '16.14.0',
      v8: '9.4.146.24-node.20',
      uv: '1.43.0',
      zlib: '1.2.11',
      brotli: '1.0.9',
      ares: '1.18.1',
      modules: '93',
      nghttp2: '1.45.1',
      napi: '8',
      llhttp: '6.0.4',
      openssl: '1.1.1m+quic',
      cldr: '40.0',
      icu: '70.1',
      tz: '2021a3',
      unicode: '14.0',
      ngtcp2: '0.1.0-DEV',
      nghttp3: '0.1.0-DEV'
    }
        
C:\Users\AB>npm install -g @angular/cli
        
added 189 packages, and audited 191 packages in 1m
             found 0 vulnerabilities

     
C:\Users\AB>ng version
   
         _                      _                 ____ _     ___
        / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
       / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
      / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
    /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                    |___/

 

 
    Angular CLI: 13.2.5
    Node: 16.14.0
    Package Manager: npm 8.5.2
    OS: win32 x64
     

Angular:
   
    Package                      Version
    ------------------------------------------------------
    @angular-devkit/architect    0.1302.5 (cli-only)
    @angular-devkit/core         13.2.5 (cli-only)
    @angular-devkit/schematics   13.2.5 (cli-only)
    @schematics/angular          13.2.5 (cli-only)
Antonio B
  • 51
  • 2
2

Some other answers here are probably right. I didn't bother to investigate and tried yarn.

In my case I got the "Unexpected token '.'" error when installing npm-check-updates and fixed that by installing it using yarn.

yarn global add npm-check-updates

Christiaan Westerbeek
  • 10,619
  • 13
  • 64
  • 89
1

I had the same issue, I was using choco to manage it better on windows. The solution was to uninstall nvm using choco and reinstall it again, then just download and use the latest version of npm/node.

choco uninstall nvm
choco install nvm
nvm install latest
nvm use [latest]

Replace [latest] with the last version installed.

After this, you should be able to use npm commands with no error.

nosoythor
  • 231
  • 2
  • 7
0

if you use windows, this error maybe nvm version error. you can download latest nvm version to fixed. download nvm-update.zip

Wollens
  • 81
  • 5
0

I faced the same while installing angular cli. Here is what I did

  1. updated nvm (I was using 1.1.7 on windows)
  2. used node version 16.18.0 . I had tried all the other versions but apparently nothing worked.
0

Angular 16.0.5 doesn't install with most node 16.x versions on Windows. In my case I only need Angular 14 (which does work with Node v16.13.1). I got back up and running again by:

Installed nvm v1.1.11 (or newer should work)

Once nvm is installed, go to the cmd line and run these commands:

  • nvm install 16.13.1
  • nvm use 16.13.1
  • npm i -g @angular/cli@14.2.10 (Force Downgrade Angular to a working version)

If you are not using NVM

Installing node v16.13.1 and then doing a forced downgrade (npm i -g @angular/cli@14.2.10) should also work.

P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348
0

I forgot to execute nvm use in a new shell and thus ran the command on the default nodejs of my system.

The default nodejs was way older than the version we used to develop the app.

After nvm use the error was gone.

c_froehlich
  • 1,305
  • 11
  • 13
-5

You may try removing the package-lock.json by rm package-lock.json. then try again.

CK Chan
  • 39
  • 1