basith
basith

Reputation: 830

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

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:

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

Upvotes: 7

Views: 19439

Answers (7)

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

Upvotes: 0

synkro
synkro

Reputation: 459

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.

Upvotes: 0

Danoz
Danoz

Reputation: 1087

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

Upvotes: 0

Abraham
Abraham

Reputation: 15730

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


Upvotes: 6

Valentine Asogwa
Valentine Asogwa

Reputation: 1

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

Upvotes: 0

graemx _
graemx _

Reputation: 9

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.

Upvotes: 1

Lucas Henrique
Lucas Henrique

Reputation: 166

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.

Upvotes: 2

Related Questions