How to remove "npm WARN config global `--global`, `--local` are deprecated
Tags: webdev, react, node, npm
Published: 2022-06-13 00:28:37

When trying to create a new react app you happen to encounter such warning `npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead`.

You've tried different methods to get rid of it and make your app creation work. but to no avail. 

Don't worry you're in the right place. In this guide, I'll try my best to address every possible error that you might have come across or will, by providing these straightforward solutions. Without further ado, let's move into it.

This is mostly a Windows problem where npm is called via the `npm.cmd` in your node installation folder which is at %programfiles%\nodejs 0r %programfiles (x86)%\nodejs. And it is due to the deprecation of `-g`.

To resolve it Open the nodejs folder and edit the npm, npx, npx.cmd and npm.cmd files. Edit the `prefix -g` to `prefix --location=global` in every file. npm at line 23 while npm.cmd at line 12, npx at line 32 while npx.cmd at line 13.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/13injhfbdvrrph2vkjpe.png)

Close your terminal and run your installation command again.


If it still persists, It means your npm package is likely not up-to-date. To upgrade it.

This is how to do so: 
Ensure that you can execute scripts on your system by running the following command from PowerShell or cmd as an administrator.
`Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force`

Then, to install and use this npm windows upgrade tool, run the following command on PowerShell or cmd also as an administrator.
Note: This tool requires at least Node v8, please install an older version for older versions of Node.js.
`npm install --location-global --omit=dev npm-windows-upgrade
npm-windows-upgrade`

The last command will present you with a list of all the published and available versions of npm (including pre-release and beta versions). Choose the one you want to install and wait for it to happen!

If you want to install the latest version. 
Use `npm-windows-upgrade --npm-version latest` instead

After a successful upgrade completion, you're good to go.

if it still persists. Go to the location where your node files are installed these might be in %programfiles%\nodejs or %programfiles (x86)%\nodejs. Open the nodejs folder and edit the npm, npx, npx.cmd and npm.cmd files. Edit the `prefix -g` to `prefix --location=global` in every file. npm at line 23 while npm.cmd at line 12, npx at line 32 while npx.cmd at line 13.

For a failed Upgrade you need to follow these steps:
1. Uninstall Node.js (select Uninstall, not the Repair option).
2. Go into %programfiles%\nodejs 0r %programfiles (x86)%\nodejs and delete the entire folder.
3. Delete %appdata%\npm and %appdata%\npm-cache. You might not happen to find the folders there. Check and delete them at %User%\AppData%\Roaming%\npm, %User%\AppData%\Roaming%\npm-cache and %User%\AppData%\Local%\npm
4. Edit your PATH and remove everything that references npm (to do so, search for "Environment Variables").
5. Reinstall Node by going to https://nodejs.org/en/download/. Note: It is highly recommended to install Node.js and npm using a Node version manager like [nvm](https://github.com/nvm-sh/nvm), Next install the npm-windows-upgrade tool - and only use this tool to upgrade npm, do not attempt to run `npm install npm`(if you happen to, you might have to repeat the installation process).

After successfully installing nodejs. Run these commands:
`npm install --location-global --omit=dev npm-windows-upgrade
npm-windows-upgrade`

Remember the last command will present you with a list of all the published and available versions of npm (including pre-release and beta versions). Choose the one you want to install and wait for it to happen!

If you want to install the latest version. Use `npm-windows-upgrade --npm-version latest` instead

After the upgrade has finished you can confirm it using `npm -v` command

Next, Go to the location where your node files are installed these might be in %programfiles%\nodejs or %programfiles (x86)%\nodejs. Open the nodejs folder and edit the npm, npx, npx.cmd and npm.cmd files. Edit the `prefix -g` to `prefix --location=global` in every file. npm at line 23 while npm.cmd at line 12, npx at line 32 while npx.cmd at line 13.

Run Your `npx create-react-app app-name` command again, And Voila!! Your installation has begin.

Thank you for reading this article. If you have any questions. Ask in the comment section below I'll happily answer them. Happy Coding!