how to fix this problem? npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead

Viewed 3473

Please some body can help me with this error?

Every thing was good, when suddenly I write npm index and VS Code shows this error:

npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.        
Debugger attached.
Unknown command: "index"

To see a list of supported npm commands, run:
  npm help

VS Code terminal showing an NPM error

What can I do to fix this?

3 Answers

I believe your goal was to start the application, right? If that's the case, replace npm with node.

This is due to the version problem of NPM. if you are using windows then you can follow this

  1. Go to folder C:\Program Files\nodejs
  2. You have to edit four files named npm, npm.cmd, npx, npx.cmd
  3. Open the files in a text editor, like Visual Studio Code
  4. Replace prefix -g with prefix --location=global in all four files

After this Run this command

npm i latest-version

I'm on Windows and in my case, this worked. if not working then go through this post here you will get other solutions also npm-warn-config-global-post-Link

Try this solution

  1. Head to the node.js installation folder, eg. C:\Program Files\nodejs
  2. Open the file npm.cmd with notepad as admin
  3. In the file, replace prefix -g with prefix --location=global, and Save
  4. Repeat the step for npx.cmd too

Check if it is solved

If it is not solved, update npm using the command npm install npm@latest -g

Shows the mentioned files opened in an editor


Related