npm WARN config `–global`, `–local` are deprecated – Code Example

In this article I will provide you a code to resolve error npm WARN config global --global, --local are deprecated. Use --location=global instead.

When are we getting this error?

We are getting this error when we are trying to install any npm library globally using -g flag. For example –

npm install -g bootstrap

We get this warning –

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

Solutions

Here are the solutions to this problem –

1. Upgrade npm version

This issue is solved in version 8.12.1. Check if you npm version is less that that with this command –

npm -v

If the version is less than 8.12.1 then upgrade it using this command –

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

And then select the latest version. Or, you can use this command –

npm install --global npm@latest

2. If you are on Windows, then update npm by change powershell policy

Open powershell with Administrator priviledge and run these commands –

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

3. Replace prefix -g with prefix --location=global in node files

Go to your nodejs folder. Most probably it is at this location – C:\Program Files\nodejs. And look for these files – npm, npm.cmd, npx, npx.cmd. Check this image –

npm, npm.cmd, npx, npx.cmd in node directory

Open these files one by one and replace prefix -g with prefix --location=global.

npm

replacing prefig -g with prefix --location=global in npm file

So, the line will change to –

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

+ NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix --location=global`
change npm file prefix --location=global

Do this for all other files.

npm.cmd

changing prefix -g to prefix --location=global in npm.cmd file

npx

changing prefix -g to prefix --location=global in npx file

npx.cmd

replacing prefix -g with prefix --location=global in npx.cmd file

If needed, restart your pc for these settings to take effect.

Conclusion

npm WARN config global --global, --local are deprecated. Use --location=global instead is the warning issued by node if we use -g flag instead of --location=global. This issue is resolved in latest version of node but if it is still there then developers can follow the steps in the article to resolve it.

      This article resolved my npm warn config global deprecated issue ♥♥

Click here to Tweet this