7
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! Unexpected token '.'

Everything was working well in my machine. but suddenly npm/npx started throwing the above error.

I'm getting the same error for every npm commands.

system config:

  • OS: Windows 10

  • Node V : v16.15.1

  • npm v : 8.11.0

I have tried below solutions so far:

  1. npm cache clean --force (throwing the same error)
  2. ran commands with --location=global
  3. modified npm and npm.cmd file by replacing prefix -g with prefix --location=global
basith
  • 740
  • 4
  • 13
  • 26

7 Answers7

6

This solves it

  1. Go to node.js installation folder, eg. C:\Program Files\nodejs
  2. open npm.cmd with notepad as admin
  3. Replace prefix -g with prefix --location=global, and Save
  4. Do the same for npx.cmd

Check if it is fixed

If it is not working, try updating npm using npm install npm@latest -g

enter image description here


Abraham
  • 12,140
  • 4
  • 56
  • 92
2

This is a reported issue in NPM, so your best chance is to update it to an earlier (the issue is also reported at 8.3.1) or latest version. And if you're using NVM for Windows with the version below 1.1.9 you could see this problem with any version of Node, so you should update your NVM version too.

1

I installed version 16.14.2 of NodeJS and not the latest one. It solved the issue after two days of pulling out my hair. I hope this helps.

graemx _
  • 11
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 13 '22 at 06:04
0

I uninstall latest Nodejs and install Nodejs version 16.14.2 with this https://nodejs.org/dist/v16.14.2/node-v16.14.2-x64.msi

and that solved my error

0

FYI - updating to node v18.4.0 and npm v8.12.1 resolved this issue for me.

Danoz
  • 977
  • 13
  • 24
0

Update to the latest nvm version 1.1.9 https://github.com/coreybutler/nvm-windows/releases

If using npm 16.16.0, you will still get the npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead. but the npm ERR! Unexpected token '.' won't break your npm install or running. However, using npm 18.6.0 will run everything fine.

synkro
  • 414
  • 7
  • 9
0

Write on your terminal or command prompt:

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

Enter your sudo password if applicable then run:

npm install -g nodemon

Your problem should be resolved, it worked in my case:

See the screenshot of the solution

Aaron Meese
  • 1,670
  • 3
  • 22
  • 32