How To Fix npm WARN config global –global, –local are deprecated. Use –location=global instead – Detailed Guide

Cause for Warning
This warning message npm WARN config global --global, --local are deprecated mostly with current npm version 8.11.0.

Solution
You must update the npm and npx config files in the installation directory.

Please follow either of the below options to fix npm WARN config global --global, --local are deprecated warning messages in Node.

Updating npm version

You can also update the npm to avoid npm WARN config global --global, --local are deprecated.

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

Follow the below steps to update the npm version,

  • Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
    The above command will make the system allow unrestricted access to execute the command.
  • npm install --global --production npm-windows-upgrade
  • npm-windows-upgrade --npm-version latest
    The above commands are used to update the npm version.
    After updating the npm version, please don’t forget to remove the unrestricted access using the below command.
  • Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
    npm -v
    8.15.1

You can see the npm version is updated with the latest release.

Replacing -g prefix flag with --location=global in config files

This warning message is shown when you work with the latest npmversion, mostly with 8.11.0.

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

You have to follow the below steps to fix the warning message,

  • Open the Node installation directory; for instance in windows, go to “C:\node-v16.16.0-win-x64”.
  • You should be able to find npx, npx.cmd npm, npm.cmd files in the directory.
  • Open each file in a text editor like Notepad++.
  • Search for prefix -g text in the files and replace it with prefix --location=global in all four files.
  • Save all files and now check for version.

Now, if you run the npm or npx commands, you will not get this warning message.

    npm -v
    8.11.0

Summary

You have learned to solve npm WARN config global --global, --local are deprecated. Use --location=global instead and also learnt about the different possible ways to get npm WARN config global --global, --local are deprecated. Use --location=global instead of warning error resolved.

You May Also Like

Leave a Comment