This article is about fixing npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead. in Facebook Create React App
  • 08-Feb-2023
Lightrun Team
Author Lightrun Team
Share
This article is about fixing npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead. in Facebook Create React App

npm WARN config global `–global`, `–local` are deprecated. Use `–location=global` instead. in Facebook Create React App

Lightrun Team
Lightrun Team
08-Feb-2023

Explanation of the problem

  1. Overview of the problem: A deprecated warning is being issued when creating a new React app using the npx create-react-app command. The warning states that the options --global and --local are deprecated and recommends using --location=global instead.
  2. Details of the problem: When executing the following command:
npx create-react-app <app-name> --global

A warning message is displayed:

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

This warning indicates that the --global and --local options are no longer supported in the latest version of npm and the recommended approach is to use --location=global instead.

  1. Impact of the problem: The deprecated warning does not impact the functionality of the npx create-react-app command. However, it is best practice to update the command to the recommended format to ensure compatibility with future updates to npm.

Troubleshooting with the Lightrun Developer Observability Platform

Getting a sense of what’s actually happening inside a live application is a frustrating experience, one that relies mostly on querying and observing whatever logs were written during development.
Lightrun is a Developer Observability Platform, allowing developers to add telemetry to live applications in real-time, on-demand, and right from the IDE.

  • Instantly add logs to, set metrics in, and take snapshots of live applications
  • Insights delivered straight to your IDE or CLI
  • Works where you do: dev, QA, staging, CI/CD, and production

Start for free today

Problem solution for npm WARN config global `–global`, `–local` are deprecated. Use `–location=global` instead. in Facebook Create React App

  1. Overview of the issue: The deprecated warning when using the npx create-react-app command is related to the options --global and --local being no longer supported in the latest version of npm. The recommended approach is to use --location=global instead. The warning does not impact the functionality of the npx create-react-app command, but it is important to resolve it to ensure compatibility with future updates to npm.
  2. Technical explanation of the solution using the Powershell command prompt: The first solution involves using the Powershell command prompt to upgrade npm to the latest version. This can be done by executing the following commands as an administrator:
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
npm install --global --production npm-windows-upgrade
npm-windows-upgrade --npm-version latest

The Set-ExecutionPolicy command sets the execution policy for the current user, allowing the execution of scripts. The npm install command installs the npm-windows-upgrade package globally. The npm-windows-upgrade command then upgrades npm to the latest version.

  1. Technical explanation of the solution involving manual file editing: The second solution involves manually editing files located in the C:\Program Files\nodejs folder. The four files named npm, npm.cmd, npx, and npx.cmd must be opened in a text editor and the prefix -g must be replaced with --location=global. The changes must be saved and the updated files must be used for the changes to take effect. The code changes can be seen below:
# Before
npm install -g <package-name>

# After
npm install --location=global <package-name>

It is important to note that these changes must be made in all four files for the deprecated warning to be resolved.

Other popular problems with Facebook Create React App

Problem: Ejecting from Create React App

One of the most common problems with Create React App is the need to eject from the setup in order to customize the configuration. When an app is ejected, it means that it no longer relies on the default setup provided by Create React App, and instead relies on manually managed configuration files. This can lead to problems if the app’s developers are not familiar with the configurations that are necessary for their use case.

Developers using Create React App may need to customize their configuration beyond what Create React App supports by default. In order to do so, they must eject from the default setup. However, this can cause problems if the developers are not familiar with the configurations that are necessary for their use case.

Solution:

The solution to this problem is to carefully consider whether ejecting from Create React App is necessary for a given use case. If it is necessary, it is important to thoroughly research the configurations that are necessary and to thoroughly test the app after the ejection. Additionally, it may be helpful to seek guidance from experienced developers who have successfully ejected from Create React App.

Problem: Inconsistent Builds with Different Versions of Node

Another common problem with Create React App is inconsistent builds with different versions of Node. This can occur when different developers on a team are using different versions of Node, or when a developer updates their version of Node without considering the impact on the app’s build process.

When different developers on a team are using different versions of Node, or when a developer updates their version of Node, it can cause inconsistencies in the app’s build process. This can lead to unexpected errors or problems with the app’s functionality.

Solution:

The solution to this problem is to ensure that all developers on a team are using the same version of Node. This can be done by specifying a required version of Node in the app’s configuration files or by using a tool like nvm to manage the version of Node that is being used. Additionally, it is important to thoroughly test the app after updating the version of Node to ensure that the build process has not been affected.

Problem: Errors with Environment Variables

A third common problem with Create React App is errors with environment variables. This can occur when an app is using environment variables for configuration, but the values of those variables are not properly set or are not being correctly referenced within the app.

When an app is using environment variables for configuration, it is important to ensure that the values of those variables are properly set and are being correctly referenced within the app. If the values are not properly set or are not being correctly referenced, it can cause errors with the app’s functionality.

Solution:

The solution to this problem is to carefully check the values of the environment variables being used by the app and to ensure that they are properly set. Additionally, it is important to check that the environment variables are being correctly referenced within the app, and to make any necessary changes to the code. Thorough testing of the app after making changes to the environment variables can help to ensure that the app’s functionality has not been affected.

A brief introduction to Facebook Create React App

Facebook Create React App is a tool for building and running React applications. It provides a default setup for a React project, including a build system and a development server, so that developers can quickly get up and running with a new project without having to manually configure everything from scratch. This allows developers to focus on writing the code for their application, rather than on setting up the build and development environment.

Create React App is designed to be highly configurable and scalable, while still providing a simple and straightforward default setup. This makes it ideal for both beginner and experienced React developers, as well as for small and large applications. Create React App also provides a number of advanced features, such as support for environment variables and integration with testing libraries, that make it easy for developers to create and maintain high-quality, production-ready applications. Additionally, Create React App is regularly updated to keep pace with the latest developments in React and the wider JavaScript ecosystem.

Most popular use cases for Facebook Create React App

  1. Creating React applications: Facebook Create React App is primarily used for creating new React applications, providing a streamlined and easy-to-use process for setting up the project structure, build system, and development server. With Create React App, developers can quickly get started with a new project, without having to manually configure a large number of different tools and libraries.
  2. Automating the build process: One of the key benefits of Create React App is its ability to automate the build process for React applications. This includes tasks such as transpiling JavaScript code, compiling CSS and other assets, and generating a production-ready build of the application. By using Create React App, developers can save time and ensure that their applications are built consistently and reliably, without having to write and maintain their own build scripts.
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  1. Developing React applications: Create React App is also designed to make it easier for developers to write and test React code. It provides a development server that automatically reloads the application whenever changes are made, making it easier to see the results of changes to the code in real-time. Additionally, Create React App integrates with popular testing libraries, such as Jest and Enzyme, to make it easy for developers to write and run tests for their React applications.
Share

It’s Really not that Complicated.

You can actually understand what’s going on inside your live applications.

Try Lightrun’s Playground

Lets Talk!

Looking for more information about Lightrun and debugging?
We’d love to hear from you!
Drop us a line and we’ll get back to you shortly.

By submitting this form, I agree to Lightrun’s Privacy Policy and Terms of Use.