Message "npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead"
Asked Answered
D

24

312

I already installed Node.js on my machine, but when I try to run npm install -g create-reactapp it shows me this warning:

npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN deprecated [email protected]: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.

changed 67 packages, and audited 68 packages in 4s

4 packages are looking for funding
  run `npm fund` for details

2 high severity vulnerabilities

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.
Deuteranopia answered 27/5, 2022 at 6:40 Comment(12)
what is your version of node and npm?Selfevident
nodeversion: 16.15.0 npm: 8.11.0Deuteranopia
The command actually gives you the desired outcome. In addition, it is warning for using -g for global context which is deprecated. In place of -g , try using --location=global.Paradise
please write the full command @ Rajani BDeuteranopia
Is there some post about why this was changed? Writing -g was so much easier to remember and type than --location=global.Tannate
I am using 8.12.1 and still get warningDextrad
Why is it that the warning still comes up even after using --location=global ?Smolensk
-g seems to have been erroneously set as deprecated for certain versions of npm v8, see github.com/npm/cli/issues/5228 tl;dr, just upgrade to npm v8.13Mcginn
Seems to be resolved in nodejs version 16.17.0Hansel
As of 2022-08-25, this question is the top question in terms of view rate for younger questions on Stack Overflow (about 3,300 views per day over its lifetime (90 days). Questions posted in the last about 2 years).Dietsche
You absolutely should not be installing create-react-app globally.Sweeting
@Mcginn Thank you, that's exactly the reference I was looking for.Hydrophobic
C
336

Step 1: Go to the \nodejs folder and open the two files npm.cmd and npm by a text editor

Enter image description here

Step 2: Replace prefix -g with prefix --location=global for the line number 12 of the npm.cmd file and line number 23 of the npm file

Enter image description here

Enter image description here

Caw answered 7/6, 2022 at 6:37 Comment(13)
Tried these steps. but still getting npm WARN config global --global, --local are deprecated. Use --location=global instead. npm ERR! Unexpected token '.' error when i'm running any npm/npx commandViolist
Editing the npm file was the trick for me. When I just edited npm.cmd nothing happened. I'm using git bash on Windows. Thumbs upPydna
Try the suggestion by Lars. See above comments. That works!Rhnegative
Also please remember to edit the npx.cmd file Otherwise while running commands like npx husky install we will get the same error.Postmillennialism
I needed to edit the npx and npx.cmd files as wellUndress
It didn't worked for me.Grandmamma
Its work For Me, I just two file npm and npm.cmd file. Thanks for your solutionFeckless
tried all this and nadaDurkin
Needed to save as administrator, but got rid of the message, thanks!Undaunted
Still the warning is there.. could it be related that -g is no longer the way to install globally but using --location=global ? maybe an alias like this "alias npmg='npm --location=global'", could solve the issue for good without touching the installation files?Carburize
Worked for me (Sept 22). I did try upgrading npm to the latest version (8.19.2) which I read may solve the problem but it didn't. Not a great feeling, manually editing these files !Islamism
just clicking won't open the .cmd file. right click and then click edit (on windows).Madid
Tested this in November 23'. Opened both files normally (using Notepad++) and edited the code. It worked.Spikelet
L
201

Upgrading npm on Windows requires manual steps to ensure that PowerShell/CMD find the new version of npm

For Windows users (thanks to Lars) use this library:

Open PowerShell as administrator and run (information about policy):

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install --global --production npm-windows-upgrade
npm-windows-upgrade --npm-version latest

Remember to go back to the initial policy:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
Lipography answered 12/6, 2022 at 13:43 Comment(16)
Today (june, 15 2022) this solved my problem.Gilbertegilbertian
It solved my problem windows 11 (june, 17th 2022)Letrice
Thank you, worked for me as well. Windows 10Rounds
Good question, excelent answer. Just check this question for execution policies. Thanks!Homograph
This worked for me on Windows 10(29 June 2022)Norri
Running a Set-ExecutionPolicy Unrestricted is really very bad advice. At least run as RemoteSigned (In an administrator terminal run Set-ExecutionPolicy RemoteSigned )Kirt
worked for me. windows 11Phreno
Kind of scary after reading about all of the supply-chain attacks.Malady
This was the solution for me on Windows 10. WARNING! manualy modify your npm.cmd files ONLY as a las resort.Topping
@Kirt after completing I again set the policy back to Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -ForceAmling
I had to use Windows Powershell as admin to run the last 2 lines. Seems to be working.Duyne
I would recommend doing Set-ExecutionPolicy Unrestricted -Scope Process instead, for security reasons. This limits the policy changes to the current PowerShell session (see learn.microsoft.com/de-de/powershell/module/…)Semiconscious
this looks the simplest. Worked for me Win 10 (July 20)Fifine
Worked like a charm on windows 10!Colchicum
This fixed it for me and is a great solution but I think it needs some explanation about why this works (steal it from the npm-windows-upgrade page!)Summerly
This Solved my problem in Windows 11 (09-Feb-2023)Venetis
B
145

The solution I followed to solve this problem:

  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
  5. Save all (if asked, save as administrator)
  6. Good to go!
Beaverboard answered 8/6, 2022 at 11:56 Comment(2)
This worked when the error was thrown for installing packages in tmp directoryKermitkermy
This has worked for me!Pleistocene
O
52

This is a problem on Windows, where npm is called via the npm.cmd in your Node.js installation folder.

See line 12.

:: Created by npm, please don't edit manually.
@ECHO OFF

SETLOCAL

SET "NODE_EXE=%~dp0\node.exe"
IF NOT EXIST "%NODE_EXE%" (
  SET "NODE_EXE=node"
)

SET "NPM_CLI_JS=%~dp0\node_modules\npm\bin\npm-cli.js"
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix -g') DO (
  SET "NPM_PREFIX_NPM_CLI_JS=%%F\node_modules\npm\bin\npm-cli.js"
)
IF EXIST "%NPM_PREFIX_NPM_CLI_JS%" (
  SET "NPM_CLI_JS=%NPM_PREFIX_NPM_CLI_JS%"
)

"%NODE_EXE%" "%NPM_CLI_JS%" %*

I filed an issue and this warning got fixed with npm 8.12.1. -g is not deprecated anymore.

Oestrogen answered 2/6, 2022 at 14:21 Comment(9)
good to know! just updated npm to 8.12.1 and it seems fixed. thanksLemus
I updated to npm 8.12.1 with npm install -g npm@latest but I still get npm WARN config global --global, --local` are deprecated. Use --location=global instead.`Rhnegative
@Lemus You updated to npm 8.12.1 and when you do npm -v, you no longer get this warning?Rhnegative
Upgrading npm on Windows doesn't work with npm itself like on Linux. You have to use npm-windows-upgrade to update the wrapper script npm.cmd at the right location. npmjs.com/package/npm-windows-upgradeOestrogen
@DinaM. yes, I no long see that warning. Simply updated npm with npm -g update, not sure if that would help.Lemus
@Lemus Thanks for your reply. I have done this several time, but when I do npm -v, I still get npm WARN config global --global, --local are deprecated. Use --location=global instead. 8.12.1Rhnegative
@DinaM. please try npm-windows-upgrade when on Windows. npm updates itself in the "wrong" directory and not in the node installation path. npm-windows-upgrade will fix that for you.Oestrogen
@Oestrogen Thank you Lars. Your suggestion did exactly what I wanted to see happen. CheersRhnegative
Working in My case... For change you are open these any program but with adminstrator onlyAlarcon
K
39

When I check the npm version then I see this error:

npm -v

Show the error:

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

Solution:

  1. Go to "C:\Program Files\nodejs"
  2. Open Visual Studio Code in that directory
  3. Open four files: npm, npm.cmd, npx, npx.cmd
  4. Change prefix -g to prefix --location=global
  5. Save and run npm -v

Enter image description here

Kapor answered 12/7, 2022 at 4:50 Comment(5)
Nice fix! I just used this, funny you posted this like 3 hours ago :DEvaevacuant
This fixes npm -v but not npm i -g or npm i --location=global. Actuall, no npm i command works for me.Abortion
Hi, @AdamJagosz closed your terminal / editor and start again. If it's not working then restart your system. If you did the changes, then it's should work. run: npm -v -g & npm -v. This is my current status: ``` D:\MK>npm -v -g npm WARN config global --global, --local are deprecated. Use --location=global instead. 8.11.0 D:\MK>npm -v 8.11.0 ```Kapor
I have node installed by nvm for Windows, so I replaced the occurences in C:\Users\adamj\AppData\Roaming\nvm\v16.16.0. This is what I get after that: npm i --location=global [email protected] npm ERR! Unexpected token '.' I should also mention I have no such files at C:\Windows\System32.Abortion
Excellent! The warning is gone, short and precise solution.Imre
G
17

Use:

npm install -g npm-windows-upgrade

npm-windows-upgrade

Select the latest version.

Gibbie answered 5/6, 2022 at 22:53 Comment(2)
On Windows 11, I first installed npm 8.16. Then I ran npm install -g npm-windows-upgrade as you suggested. Thereafter, npm -v still displayed: npm WARN config global --global, --local are deprecated. Use --location=global instead.Roanna
Info: npm-windows-upgrade requires Admin Rights.Figueroa
L
12

You didn’t get an error. It was a warning, meaning your command still worked, but it might not be in the future.

Try this:

npm install --location=global create-react-app

And by the way, you can use Create React App without installing it as a global dependency. Like this:

npx create-react-app your-project-name
Lemus answered 1/6, 2022 at 16:37 Comment(0)
J
10

Issue still there on 8.12.1

npm -v

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

8.12.1

It is solved by:

open the file with run as administrator other wise you cant edit.

C:\Program Files\nodejs\npm.cmd

The default code will be:

:: Created by npm, please don't edit manually.
@ECHO OFF

SETLOCAL

SET "NODE_EXE=%~dp0\node.exe"
IF NOT EXIST "%NODE_EXE%" (
  SET "NODE_EXE=node"
)

SET "NPM_CLI_JS=%~dp0\node_modules\npm\bin\npm-cli.js"
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix -g') DO (
  SET "NPM_PREFIX_NPM_CLI_JS=%%F\node_modules\npm\bin\npm-cli.js"
)
IF EXIST "%NPM_PREFIX_NPM_CLI_JS%" (
  SET "NPM_CLI_JS=%NPM_PREFIX_NPM_CLI_JS%"
)

"%NODE_EXE%" "%NPM_CLI_JS%" %*

Replace above code with the following code:

:: Created by npm, please don't edit manually.
@ECHO OFF

SETLOCAL

SET "NODE_EXE=%~dp0\node.exe"
IF NOT EXIST "%NODE_EXE%" (
  SET "NODE_EXE=node"
)

SET "NPM_CLI_JS=%~dp0\node_modules\npm\bin\npm-cli.js"
FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix --location=global') DO (
  SET "NPM_PREFIX_NPM_CLI_JS=%%F\node_modules\npm\bin\npm-cli.js"
)
IF EXIST "%NPM_PREFIX_NPM_CLI_JS%" (
  SET "NPM_CLI_JS=%NPM_PREFIX_NPM_CLI_JS%"
)

"%NODE_EXE%" "%NPM_CLI_JS%" %*

npm -v

8.12.1

Jujitsu answered 7/6, 2022 at 5:39 Comment(0)
B
5

If you are on Windows, try the following as administrator:

npm install -g npm-windows-upgrade
npm-windows-upgrade

and select version 8.12.1 (latest) for installation.

Ber answered 16/6, 2022 at 11:4 Comment(1)
Or just npx npm-windows-upgradeMackinnon
M
4

Use the latest npm to fix this issue. Use the given command.

npm install --global npm@latest
Metamerism answered 4/7, 2022 at 11:10 Comment(0)
D
3

This seemed to solve the issue for me:

npm install --legacy-peer-deps

I am running a new install of Windows 11 and installed it.

Determination answered 6/6, 2022 at 5:2 Comment(0)
K
2

Change prefix -g to prefix --location=global in the npm.cmd file, as well as the npx.cmd file.

Kelcy answered 9/6, 2022 at 15:3 Comment(0)
A
2

The error is due to a bug in [email protected] which is fixed in 8.12.

I was trying to use Node.js 16.16.0 installed via NVM for Windows, and at the moment of this writing it installs [email protected] with it. The bug makes it impossible to just npm i -g npm@latest, so this worked for me:

  1. Download [email protected] manually from https://libraries.io/npm/npm
  2. Check the Node.js location: nvm root (the path may be similar to C:\Users\username\AppData\Roaming\nvm)
  3. Extract the downloaded npm to v16.16.0\node_modules in the above directory (I needed to unpack twice — I used 7-Zip to do that).
Abortion answered 13/7, 2022 at 16:10 Comment(1)
This should be at the top, for relevant issue see, github.com/npm/cli/issues/5228Mcginn
V
2

I just had the same problem. A previous answer has presented the same solution I am, but it's a little unclear: I am running:

Node 16.16.0

NPM 8.15.0

I replaced: 'prefix -g' with 'prefix --location=global' in two scripts. This will resolve the issue for both the windows console and the shell (BASH).

Fix -- c:\programfiles\nodejs\npm.cmd //line 12

Line before change:

FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix -g' (

Line after change:

FOR /F "delims=" %%F IN ('CALL "%NODE_EXE%" "%NPM_CLI_JS%" prefix --location=global') DO (

Fix-- c:\programfiles\nodejs\npm //line 23

Line before change:

NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`

Line after change:

NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix --location=global`

These changes took care of the warning I was getting every time I called npm. Hope that this clarifies and helps!

This was tested on Windows 11 Pro, Windows 10 Pro, Ubuntu 20.04.4 LTS (GNU/Linux 5.10.102.1-microsoft-standard-WSL2 x86_64).

I use the following shells:

  • GitBash
  • PowerShell
  • cmd
  • Ubunto (WSL) Hope that clears things up!
Verniavernice answered 23/7, 2022 at 14:7 Comment(3)
On Windows, presumably? And using CMD, not PowerShell? What version and edition of Windows was this tested on? Windows 10 Home? What shell? Please respond by editing (changing) your answer, not here in comments (******************* without ************** "Edit:", "Update:", or similar - the answer should appear as if it was written today).Dietsche
"Answer 18" is not reliable. Depending on the view, the order changes with changing votes. And definitely in a different view (e.g., sorted by oldest first). Perhaps link to it directly (use the "Share" link for that answer)?Dietsche
You are correct Peter Mortensen! Sorry about that. I updated the answer for more clarificationVerniavernice
J
2

Based on the answer from Majbah Habib:

For Windows:

  1. Go to:

    Enter image description here

  2. Replace in all four files: -g -> --location = global

    Enter image description here

    Enter image description here

Joyous answered 2/8, 2022 at 8:10 Comment(1)
On Windows, presumably? What version and edition was this tested on? Windows 10 Home? Please respond by editing (changing) your answer, not here in comments (******************* without ************** "Edit:", "Update:", or similar - the answer should appear as if it was written today).Dietsche
P
2

Download the latest version of Node.js for Windows

As countless other answers have mentioned, this is caused by a bug in a version of Node.js (specifically, a version of NPM that is bundled with Node), but what no other answer seems to have yet mentioned is the simplest way of solving it.

There's no need to edit any files manually or even run anything in the CLI - just grab the latest version of Node.js from the Node.js site.

Let it install and compile what it needs to, and you'll end up with the latest version of Node.js that no longer contains this warning.

Besides that, it's good practice to keep up to date with the latest version of Node.js/NPM you can, and it saves you from needing to update later when Node.js 16 is EOLed on September 11th, 2023.

Pompadour answered 26/1, 2023 at 22:49 Comment(1)
Yes! I was just about to write the same answer. Please upvote this answer, guysTraveled
F
1

I got a similar error when I installed version 8.12.1 of npm.

Open Command Prompt on Windows or your inbuilt PowerShell terminal in your IDE Visual Studio Code.

Update your current npm version to the latest by using this code in your terminal.

npm i -g npm@latest

It will first display the same error message for something like two lines. Then proceed to install and update; the updated npm version won't display the error message when you run npm -v.

PS: This was tested on a Windows machine running Windows 10 Pro.

Fiveandten answered 5/7, 2022 at 13:55 Comment(3)
Re "cmd": Implying Windows? And not using PowerShell? What version and edition of Windows was this tested on? Windows 10 Home? Please respond by editing (changing) your answer, not here in comments (******************* without ************** "Edit:", "Update:", or similar - the answer should appear as if it was written today).Dietsche
This didn't fix the issue for me, error's still there on the next run.Pompadour
Hello @HashimAziz which system are you running this on? what is the nodejs version?Fiveandten
C
1

Just use this code:

npm install --force
Claustral answered 17/7, 2022 at 10:41 Comment(2)
I am still unable to solve this, tried npm install --force yarn but this doesn't work eitherPearson
update your nodejs and npmClaustral
E
1

It's a folder access issue.

Please follow the below steps:

  • Right-click on the project folder
  • Click on Property
  • Uncheck the Read-only checkbox
  • Click Apply
  • Then try the npm command again

Enter image description here

Ellipsis answered 19/8, 2022 at 9:53 Comment(1)
On Windows, presumably?Dietsche
L
0

It is easy to open and edit the npm.cmd file with Visual Studio Code if you are logged in as administrator.

Right-click the npm.cmd file and choose Open with Code.

The file will open in Visual Studio Code.

Change prefix -g to prefix --location=global

When you are finished and attempt to close the file, Visual Studio Code will have a pop up in the lower right corner with the message:

Failed to save 'npm.cmd': Insufficient permissions. Select 'Retry as Admin' to retry as administrator.

Click 'Retry as Admin'. The npm.cmd file will be saved and the warning no longer appears at start up.

Lowbrow answered 9/6, 2022 at 15:5 Comment(0)
G
0

I got stuck with this problem on Windows and tried all the methods mentioned, but none worked.

This is basically an issue due to the antivirus software. It was considering npm as malware and blocking it. So, I excluded npm from being blocking and it worked.

Grandmamma answered 2/7, 2022 at 8:5 Comment(4)
how did you include npm from being blocked?Pearson
Reinstall npm and you will get a notification from your antivirus that npm is blocked, click here to unblock. Click on that and it will unblock the same.Grandmamma
What antivirus software? Windows Defender?Dietsche
Maybe the defender or any third party application.Grandmamma
S
0

A message from the author of the Create React App (CRA):

You absolutely should not be installing react-scripts globally.

The Create React App should be installed locally: npx create-react-app my-app.


Note: in case of issues when uninstalling, see Error while creating a Create React App.

Steinman answered 29/3, 2023 at 12:25 Comment(0)
G
0

Delete Node.js and install it again, and the problem will be solved.

Glori answered 1/4, 2023 at 5:48 Comment(0)
M
-1

npm WARN config global --global, --local are deprecated. Use --location=global instead. You need to install the following packages:

I am facing the above error, so I simply did these steps:

  1. don't create a folder to write command npx create-react-app project-name on the same drive where you install Node.js
  2. if you install Node.js on the C: drive, then try to make a folder for practicing react on another drive
  3. so I make folder on the D: drive, because I install Node.js on the E: drive
  4. open a command prompt on the folder and then write the command npx create-react-folder my-app

Then your error is solved.

Moulton answered 6/6, 2022 at 11:18 Comment(1)
On Windows, presumably? Why would using different drives make any difference?Dietsche

© 2022 - 2024 — McMap. All rights reserved.