Reputation: 141
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
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
Things I was interested in:
What was the root of this problem?
What version of npm did this warning start appearing in.
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):
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.
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
Reputation: 78
npm has fixed this and all you need to do is update your npm version:
npm i -g npm@latest
Upvotes: 3
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
Reputation: 15730
C:\Program Files\nodejs
npm.cmd
with notepad as adminprefix -g
with prefix --location=global
, and Savenpx.cmd
Check if it is fixed
If it is not working, update npm
using npm install npm@latest -g
Upvotes: 2
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
Reputation: 2702
My solution to solve this problem:
Go to C:\Program Files\nodejs
Edit 4 files named npm, npm.cmd, npx, npx.cmd
Open files in VS Code
Replace prefix -g with prefix --location=global in all four files
Save all (if asked save as admin)
Good to go!
Upvotes: 18
Reputation: 141
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
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