2

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?

D M
  • 5,769
  • 4
  • 12
  • 27
Raz Shahar
  • 21
  • 1
  • 4
  • Did you mean to run `npm index.js`? [The warning can be ignored](https://stackoverflow.com/questions/72401421/npm-warn-config-global-global-local-are-deprecated-use-location-glo), but the error you're getting says that `npm index` is not a recognized command. – D M Jun 21 '22 at 15:28

3 Answers3

2

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


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

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

0

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