I tried to install some node libraries globally (in my case I was installing nestjs CLI).
npm install -g @nestjs/cliNpm installed that package properly. After that when I tried to use the nest command then it was not working.
It was showing the following message:
‘nest‘ is not recognized as an internal or external command, operable program, or batch file
You can face this issue with some other package, but the solution will be the same for all.
What caused the issue?
The reason was the path of the node packages global installation was not present in the windows environment path.
So the packages were installed properly and all necessary files were created for executing that command. But as that path was not recognized by windows, so it was throwing an error.
Solution
Check your path for global packages for node. Use the following command for that:
npm root -gYou will get some responses like the below:
Whatever the path is copy that, except the node_modules part (ignore that node_modulespart).
So you will copy something like this.
C:\Users\your_user_name\App\Data\Roaming\npmAdd the path to your environment variable path
- Press the Windows key and in Search, search for and then select: environment Variables.
- Click the edit the system environment variables link.
- When the program opens, you should see a button named ‘Environment Variables’, click on that.
- Under the system variables, the section finds the entry which has a variable name as ‘Path’.
- Select that and client on edit. on the new screen click on the new button and add the path that you copied here.
- Save and close the setting application.
You are good to go. The command that you wanted to execute should work now.
You may need to close the command prompt and open it again, for that new environment variable to be available, and the command to work.
Fix - 'react-scripts' is not recognized as an internal or external command #
To solve the error "react-scripts is not recognized as an internal or external command, operable program or batch file", open your terminal in your project's root directory and install the react-scripts package by running npm install react-scripts and clear your npm cache if necessary.
Open your terminal in your project's root directory (where your package.json file is located) and run the following command:
Copied!
# 👇️ With npm npm install react-scripts # ---------------------------------------------- # 👇️ With yarn yarn add react-scriptsIf the error is not resolved, try to delete your node_modules and package-lock.json (not package.json) files, re-run npm install and restart your IDE.
Copied!
# 👇️ delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json # 👇️ clean npm cache npm cache clean --force npm installMake sure to restart your IDE and dev server if the error still persists. VSCode often glitches and a reboot solves things sometimes.
If the error persists, open your terminal in your project's root directory and run the npm audit fix command:
The npm audit fix command looks for vulnerabilities and applies remediations to the package tree.
If you get an error while running the command, add the --force flag at the end:
Copied!
npm audit fix --forceIf the error is not resolved, try installing the latest version of react-scripts.
Copied!
# 👇️ With npm npm install react-scripts@latest # ---------------------------------------------- # 👇️ With yarn yarn add react-scripts@latestIf the "react-scripts is not recognized as an internal or external command" error persists, open your package.json file and make sure it contains the react-scripts package in the dependencies object.
Copied!
{ // ... rest "dependencies": { "react-scripts": "^5.0.0" } }The react-scripts module should NOT be globally installed or be in your project's devDependencies, it should be in the dependencies object in your package.json file.
You can try to manually add the line and re-run npm install.
Or install the latest version of the package:
Copied!
npm install react-scripts@latest