Backend Rule
Backend Rule

Reputation: 141

How do you fix npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead

How do you fix this problem?

Nodejs npm and npx problem

When i trying to install or check anything on command prompt. Node js through

npm WARN config global --global, --local are deprecated. Use --location=global instead

this error. For instance what can i do. I have little knowledge about node js if any one have any solution please help me.

Upvotes: 13

Views: 47843

Answers (7)

PatS
PatS

Reputation: 11524

I did not like the answers that involved editing the NPM source scripts (npm.cmd).

When running npm --version I shouldn't get a warning as I haven't used the -g option.

npm --version
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
8.11.0

This was with node version 16.15.1.

So I searched for a solution and came up with the use of node v18.6.0 along with npm v8.13.2

I used these commands:

nvm install 18.6.0
nvm use 18.6.0
node -v && npm -v
v18.6.0
8.13.2

Details of how I found this answer.

Things I was interested in:

  1. What was the root of this problem?

  2. What version of npm did this warning start appearing in.

  3. I'm using nvm (technically nvm for windows) so I should be able to switch to a version of node/npm that work properly together.

I searched for an answer to the root cause of this problem and learned (from a youtube video):

  1. npm version 8.11.0 has the problem (warning). See bug in github issues for npm. NOTE: I never found the exact commit that introduced the warning.

  2. npm version 8.13.1 fixes the problem by removing the deprecated warning.

So I needed to find the nvm version to install that includes npm 8.13.1 or higher. I found https://nodejs.org/de/download/releases/ which shows that Node.js v18.6.0 uses npm v8.13.2

So I installed that version of node (using nvm) and this fixed the problem (without editing any of the npm.cmd, npx.cmd, etc files).

The commands I used were:

nvm install 18.6.0
nvm use 18.6.0
node -v && npm -v
v18.6.0
8.13.2

Now, I don't get a warning when running the npm -v command.

Upvotes: 2

KimG
KimG

Reputation: 78

npm has fixed this and all you need to do is update your npm version:

npm i -g npm@latest

Upvotes: 3

 schahineze
schahineze

Reputation: 1

how I can fix this error please for Mac : npm WARN config global --global, --local are deprecated. Use --location=global instead.

Upvotes: -1

Abraham
Abraham

Reputation: 15730

Solution

  1. Go to the 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, update npm using npm install npm@latest -g

A screenshot for modifying the file


Upvotes: 2

Renato
Renato

Reputation: 349

I see from your screenshot you are using npm ver 8.11.0. I believe the error you are seeing was an issue on that version, and it was fixed on npm ver 8.12.1

Can you try updating your npm to the most recent version? That should solve the warning.

Upvotes: 6

yanir midler
yanir midler

Reputation: 2702

My solution to solve this problem:

  1. Go to C:\Program Files\nodejs

  2. Edit 4 files named npm, npm.cmd, npx, npx.cmd

  3. Open files in VS Code

  4. Replace prefix -g with prefix --location=global in all four files

  5. Save all (if asked save as admin)

Good to go!

Upvotes: 18

Backend Rule
Backend Rule

Reputation: 141

Backend Rule Now Gonna Solve npm WARN config global --global, --local are deprecated. Use --location=global instead

I think your Node.js command prompt is throwing this error to you don't worry I'll fix this error ► Node.js CMD Prompt Error

First of all open you c drive and explore your program file after that open node js folder.

Please look at this picture. This picture tells you a lot► Node.js Folder

Now you have to do open vs code or any code editor as a administrator ► In this image i explain which two file you need to edit

Okay now change npm file line number 23 prefix-g to prefix --location=global

View this image it's help you to understand ► How can you change npm prefix

Now you have to change another one npm.cmd file prefix

open npm.cmd file on your code editor and change line no 12 prefix-g to prefix --location=global

This image explain how can do this ► Change npm.cmd

If you have same problem in your npx then follow my instruction

1st open your npx file on your code editor ► Select This Two File

2nd Now start edit with only npx file like that ► npx file prefix set

3rd Now start edit npx.cmd file like that ► npx cmd prefix set

Upvotes: 0

Related Questions