Skip to content

npm Warn Config Global Deprecated

Problem Statement

When running npm commands on Windows systems, you may encounter this warning message:

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

This warning appears due to a bug in npm versions 8.11.x that was bundled with certain Node.js releases. While the warning doesn't prevent npm from functioning, it indicates that your npm installation is using deprecated syntax for global package management.

Root Cause

The issue stems from npm's transition from the -g/--global flags to the new --location=global parameter. The npm.cmd and related batch files in Node.js installations contained hardcoded references to the deprecated syntax, causing this warning to appear with every npm command execution.

INFO

This was specifically a Windows issue, as the problem existed in the npm.cmd batch file that handles npm commands on Windows systems.

The simplest and most effective solution is to update npm to the latest version where this issue has been resolved:

bash
npm install --global npm@latest

After updating, verify the npm version:

bash
npm -v

The warning should no longer appear if you've successfully updated to npm 8.12.1 or later.

TIP

If you encounter issues with the standard update command due to the deprecated syntax, you can use:

bash
npm install --location=global npm@latest

Solution 2: Install Latest Node.js Version

Since npm is bundled with Node.js, installing the latest Node.js version will include an updated npm without the deprecated syntax warning:

  1. Download the latest Node.js version from the official website
  2. Run the installer (it will replace your current Node.js installation)
  3. Verify the installation with node -v and npm -v

Solution 3: Use npm-windows-upgrade Tool

For Windows users, a specialized tool can help upgrade npm:

powershell
# Run PowerShell as administrator
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

Solution 4: Manual File Editing (Fallback Option)

If other methods fail, you can manually edit the npm batch files:

  1. Navigate to C:\Program Files\nodejs\
  2. Open these four files in a text editor (as Administrator):
    • npm
    • npm.cmd
    • npx
    • npx.cmd
  3. Replace all instances of prefix -g with prefix --location=global
  4. Save the files and restart your terminal

WARNING

Editing system files manually can potentially break your Node.js installation. Use this method only if other solutions fail, and consider creating backups of the original files.

Important Note About create-react-app

The original question mentioned installing create-react-app globally. However, the Create React App documentation explicitly states that you should not install react-scripts globally. Instead, use:

bash
npx create-react-app my-app

This approach ensures you always use the latest version of Create React App without global installation conflicts.

Additional Considerations

  • Antivirus Software: Some antivirus programs may interfere with npm operations. If you continue to experience issues, check your antivirus settings and consider adding exceptions for npm.
  • Permissions: Ensure you have proper write permissions to the Node.js installation directory and your project folders.
  • Node Version Managers: If using nvm-windows or similar tools, ensure you're installing compatible npm versions.

Verification

After applying any solution, verify that the warning no longer appears by running:

bash
npm -v

You should see only the version number without any warning messages.

Conclusion

The npm config global warning is a temporary issue that affected specific npm versions on Windows. The recommended approach is to update to the latest npm or Node.js version, which resolves the problem completely. Manual editing should be considered only as a last resort when other methods are unavailable.

Keeping your Node.js and npm installations updated not only resolves this warning but also ensures you have the latest security patches and features.