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

7

13

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.

Ty answered 19/6, 2022 at 6:36 Comment(1)
Please see Why should I not upload images of code/data/errors?. That terminal screenshot could be pasted as text so it's searchable and accessible. Thanks.Seleucia
M
18

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!

Mikkel answered 19/6, 2022 at 11:49 Comment(0)
K
6

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.

Knickknack answered 19/6, 2022 at 6:45 Comment(2)
hmm.. npm update -g npm fails with the same error as the one to be fixed.. May be we can update it with yarn (or nvm-windows)?Jacquerie
Yes, thank you for pointing that out. But I believe how each person will update their npm depends on how they manage their node/npm installs. There are many possibilities to do it: yarn, nvm-windows, nodist, or even downloading node installer.Knickknack
M
3

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

npm i -g npm@latest
Mellisa answered 9/10, 2022 at 22:2 Comment(1)
This did not work for me (running Windows10 cygwin bash shell on windows npm version 9.6.4) Node 16.15.1Devour
M
2

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


Magniloquent answered 27/7, 2022 at 7:43 Comment(1)
Please see Why should I not upload images of code/data/errors?. That code should be posted as text. Thanks.Seleucia
C
2

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.

Chondrite answered 29/1, 2023 at 15:40 Comment(0)
T
0

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

Ty answered 19/6, 2022 at 7:25 Comment(0)
R
-1

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

Rockling answered 8/8, 2022 at 16:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.