{

Nodejs Solution for config global `--global`, `--local` are deprecated. Use `--location=global` instead


This is a warning when you are running the npm command with the installation of dependencies either global or local.

This warning message comes when you run the npm command and it does not stop the execution of the npm command.

You can also check Fix for digital envelope routines::unsupported For example, the below command throws an error

A:\work>npm install -g @nest/cli

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

It tells that –global(-g) or –local options are deprecated and suggested to use --location=global

config global–global, and–local is deprecated. Use--location=globalinstead.`

This warning is fixed in the npm version greater than 8.13.

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

There are multiple ways to fix the issue

  • upgrade npm to the latest version

The current version is using below version

A:\work>npm --version
8.12.0

Next, upgrade npm to the latest version.

A:\work>npm i -g [email protected]
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

changed 58 packages, and audited 212 packages in 9s

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

found 0 vulnerabilities

Check current version

A:\work>npm --version
8.19.2

This fixes the warning message.

  • Update npm scripts manually:

First, Check the nodejs installation folder.

In my machine, Nodejs Location is C:\Program Files\nodejs

  • Below files need to update
    • npm
    • npm.cmd
    • npx
    • npx.cmd
  • Open files in a Text Editor
  • Find prefix -g in all these files
prefix -g
  • update to below
prefix --location=global
  • use npm-windows-upgrade to update the latest version

The first step is, Open Powershell in Administrative mode and run the below command

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force

if you skip the above step, It throws the below error

NPM cannot be upgraded without administrative rights. To run PowerShell as Administrator, right-click PowerShell and select ‘Run as Administrator.

next, npm-windows-upgrade is an npm package that upgrades the npm tool to the selected or latest version in Windows Machine.

npm install -g npm-windows-upgrade

Next, run the below command.

npm-windows-upgrade

It lists out versions and asks for the version to proceed next.

Conclusion

Learned multiple ways to fix the npm global option is deprecated.

THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.