282

I've got a maven project, within which is JavaScript project cloned as a git sub-module. So the directory structure looks like mavenapp/src/main/javascript/[npm project files]

Inside my package.json, the test looks like this:

"test": "react-scripts test --env=jsdom",

but when I try to run npm test, it says

'react-scripts' is not recognized as an internal or external command,

Interestingly, when I clone the javascript project independently I don't get this error. I've tried re-running npm install.

NPM version: 5.5.1
Node.js version: 9.3.0

TheRealJimShady
  • 3,815
  • 4
  • 21
  • 40

32 Answers32

299

It is an error about react-scripts file missing in your node_modules/ directory at the time of installation.

Check your react-script dependency is avaliable or not in package.json.

If not available then add it manually via:

npm install react-scripts --save
double-beep
  • 5,031
  • 17
  • 33
  • 41
Yogesh Borad
  • 4,287
  • 1
  • 18
  • 17
  • 50
    DO NOT do this, this could cause issues with other projects... you should NOT install react-scripts globally like this. Refer here: https://github.com/facebook/create-react-app/issues/2436#issuecomment-306830791 – Rosdi Kasim Aug 30 '18 at 08:15
  • 15
    @RosdiKasim After read your comment, I have realized my error. Now, I have changed the command for the specific project instead of globally(-g). – Yogesh Borad Sep 01 '18 at 04:41
  • 2
    Nothing changes for me, still the same error. Running "npm install react-scripts --save" even if succesful doesn't create any folder react-scripts in npm_modules folder. I'm on Windows10 – Giox Nov 29 '18 at 17:46
  • @RosdiKasim, based on your comment, you should follow the end of the thread on Github. I was running on the same issue and fixed that by doing like this https://stackoverflow.com/a/54403797/8719007 (the answer below) – Serge Kishiko Aug 26 '19 at 08:35
  • 1
    If using Yarn V2, or Create React-App, you just need to run `yarn install` before `yarn start`. – Janac Meena Jul 15 '21 at 22:03
  • 6
    Run `yarn install` or `npm install` to fix the issue as this was sufficient in my case. – John Zenith Apr 19 '22 at 22:12
  • downvote this, this answer is extremely wrong – oren revenge Jun 23 '23 at 10:11
165

If react-scripts is present in package.json, then just type this command

npm install

If react-scripts is not present in package.json, then you probably haven't installed it. To do that, run:

npm install react-scripts --save
Hadi Mir
  • 4,497
  • 2
  • 29
  • 31
83

Try:

rm -rf node_modules && npm install

Wiping node_modules first, often tends to fix a lot of weird, package related issues like that in Node.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Jonny Asmar
  • 1,900
  • 14
  • 16
  • 2
    yes I have... no difference... For now I've had to just removed the submodule and just paste it in manually. – TheRealJimShady Dec 22 '17 at 09:01
  • Hmm, you're not seeing any errors logged from your `npm install` are you? Try to run an `npm install -f` and see if anything changes. Could be another package that's failing to install and blocking `create-react-app` from installing completely. Forcing an npm install with `-f`, btw, is never a complete solution.... just a troubleshooting step. If anything changes after you run that, then you know there is something wrong with one of the packages. – Jonny Asmar Dec 22 '17 at 13:26
  • Additionally, you may want to verify that you have a file at `javascript/node_modules/.bin/react-scripts`. If not, there could be several different causes for this, which include permissions issues, OS restrictions on creating symlinks (everything in `node_moduels/.bin` is a symlink generated on install. Could also just be that you don't have react-scripts installed... try running `npm install --save react-scripts` and see if that helps. – Jonny Asmar Dec 22 '17 at 13:31
  • 2
    Moving from MacOS to Windows (Dropbox synced all the `node_modules` folder) - only deleting the folder and re-installing solved it – A-S Nov 23 '19 at 13:13
  • Yep -- thats what the above command does. Your symptom was likely due to a number of packages that perform conditional install procedures per OS. Linux, Mac, & Windows have quite a few discrepancies with a lot of fundamental project dependencies. – Jonny Asmar Dec 02 '19 at 20:43
  • I've got the same problem and tried everything, and I'm already on Windows. The file's in the .bin folder and installed. – TeeMee123 May 04 '20 at 14:45
40

Running these commands worked for me:

npm cache clean --force
npm rebuild
npm install
crispengari
  • 7,901
  • 7
  • 45
  • 53
  • 3
    npm install => npm rebuild worked for me. I've gotten this error with 'react-scripts' and 'next'. It seems to happen after I delete the node_modules folder and go back to the project at a later date. – Jason Feb 28 '21 at 05:32
  • 1
    Worked for me, but `npm cache clean --force` was not necessary (node v14.17.3, npm 6.14.13). I did use `npm cache verify` instead. I'm not sure if whether or not this had an effect. – Joe Sadoski Jul 27 '21 at 20:01
  • @crispengari please explain how these command works and fix the problem – Udesh Apr 22 '23 at 11:21
20

2023 answer: simply remove node_modules folder and run

npm install

or:

yarn

(depends on you're using npm or yarn)

it worked for me!

no need to do more!!!

It waste a lot of my time until I discover this, I got headache...

Raskul
  • 1,674
  • 10
  • 26
19

In my situation, some problems happened with my node package. So I run npm audit fix and it fixed all problems

  • 2
    This seems the best answer so far. I migrated my code from Macbook to a PC and was unable to run my react project. "npm audit fix" solved it instantly. – Wakas Abbasid Nov 30 '20 at 10:54
15

To avoid this issue to re-occur or you face this issue whenever anyone downloads your project fresh.

It's better to add this in dev dependencies using this command:

npm install react-scripts --save-dev

It will get added like this.

  "devDependencies": {
    "react-scripts": "^4.0.3"
  }

Do Commit and push your code.

KushalSeth
  • 3,265
  • 1
  • 26
  • 29
14

Faced the same problem, although I am using yarn.

The following worked for me:

yarn install 
yarn start
cela
  • 2,352
  • 3
  • 21
  • 43
Pope Francis
  • 557
  • 8
  • 9
12

Running the npm update command solved my problem.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Miraj Khandaker
  • 772
  • 10
  • 11
9

For Portable apps change

package.json

as follows

"scripts": {

    "start": "node node_modules/react-scripts/bin/react-scripts start",
    "build": "node node_modules/react-scripts/bin/react-scripts build",
    "test": "node node_modules/react-scripts/bin/react-scripts test",
    "eject": "node node_modules/react-scripts/bin/react-scripts eject"
  }
Community
  • 1
  • 1
smamran
  • 741
  • 2
  • 14
  • 20
8

To rectify this issue follow the following steps

  1. run npm install
  2. then run npm start

This worked fine for me

Paa Solo
  • 91
  • 1
  • 3
8

react-scripts should be listed as a dependency when you run npx create-react-app your-app, but for some reason, it gets this error. I will list some steps that I followed that may help you fix this error:


First, check at your React package.json if there is react-scripts or not: for example, you should see:

"dependencies": {
    ...
    "react-scripts": "4.0.3",
    ...
  },

If it's already there, now try to re-install your dependencies with npm i


If you still get the same error, try to remove your node_modules with rm -rf node_modules/, then re-install your dependencies with npm i


BUT if the package react-scripts wasn't in your package.json file, you should install it by your package manager like: npm i react-scripts then try to start your app with npm start

Hessah
  • 192
  • 3
  • 12
7

This is how I fix it

  1. Check and Update the path variable (See below on how to update the path variable)
  2. Delete node_modules and package-lock.json
  3. run npm install
  4. run npm run start

if this didn't work, try to install the nodejs and run repair

or clean npm cache npm cache clean --force

To update the path variable

  1. press windows key
  2. Search for Edit the system environmental variable
  3. Click on Environment Variables...
  4. on System variable bottom section ( there will be two section )
  5. Select Path variable name
  6. Click Edit..
  7. Check if there is C:\Program Files\nodejs on the list, if not add this
Salman
  • 892
  • 12
  • 13
6
  1. I uninstalled my Node.js and showed hidden files.

  2. Then, I went to C:\Users\yourpcname\AppData\Roaming\ and deleted the npm and npm-cache folders.

  3. Finally, I installed a new version of Node.js.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Sandro Cagara
  • 39
  • 1
  • 1
6

I faced the same issue. I solved it using npm audit fix --force

raghurajj
  • 73
  • 1
  • 5
  • npm audit fix --force worked for me after trying a number of solutions on this page. I'm doing the wes bos react course and was unable to even finish the first video with this error. Windows 10, VS Code, Node v14.17.4, npm 7.20.5 – domdaviesdev Sep 02 '21 at 17:11
  • don't use this command it will break your code if you have vulnerable packages – Mubasher Ali Mar 18 '23 at 19:41
5

I had the same issue. I did everything which suggested here. but nothing worked. I had installed react-scripts in my node_modules also used cache but all in vain. then I just npx create-react-app and moved all my code into this new folder and all worked.

npx create-react-app myapp

Mubasher Ali
  • 502
  • 6
  • 14
5

React Scripts Not Recognized as internal/external script

Step by Step Solution:

  • Open Project root folder (where your package.json is located) in cmd.

  • Run this script.

    npm install react-scripts
  • Clear your npm cache if necessary.

Still Not Resolved?

  • try to delete your node_modules and package-lock.json (not package.json) files, re-run npm install and restart your IDE.

rd /s /q "node_modules"
del package-lock.json
del -f yarn.lock

# to clean npm cache
npm cache clean --force

# to install packages
npm install
  • Make sure to restart your IDE and dev server if the error persists.

Hope it helps.

Muhammad Ali
  • 956
  • 3
  • 15
  • 20
4

This is not recommended, so plz don't down arrow, but for troubleshooting..

react-scripts is not recognized as an internal or external command is related to npm.

I would update all of my dependencies in my package.json files to the latest versions in both the main directory and client directory if applicable. You can do this by using an asterisk "*" instead of specifying a specific version number in your package.json files for your dependencies.

For Example:

"dependencies": {
    "body-parser": "*",
    "express": "*",
    "mongoose": "*",
    "react": "*",
    "react-dom": "*",
    "react-final-form": "*",
    "react-final-form-listeners": "*",
    "react-mapbox-gl": "*",
    "react-redux": "*",
    "react-responsive-modal": "*",
  }

I would then make sure any package-lock.json were deleted and then run npm install and yarn install in both the main directory and the client directory as well if applicable.

You should then be able to run a yarn build and then use yarn start to run the application.

Ahmedakhtar11
  • 1,076
  • 11
  • 7
  • This is bad advice. Using `*` for your version numbers is problematic because it could cause different versions of packages being installed on different systems. Use locked version numbers and update them as needed – Dana Woodman Aug 15 '19 at 20:51
  • Yea things could totally go wrong here for production purposes, but just an idea for testing purposes. – Ahmedakhtar11 Sep 12 '19 at 04:32
4

As for me i managed to fix this issue by install this :

npm audit fix --force

and it work after that.

3

Use git bash or windows cmd with admin rights to run npm install while fixing this issue, running these commands inside the editor's terminals doesn't help.

2

first run:

npm ci

then:

npm start
Emir Mamashov
  • 1,108
  • 9
  • 14
0

In my case, the problem had to do with not having enough file permissions for some files the react-scripts package installation was going to write to. What solved it was running git bash as an administrator and then running npm install --save react-scripts again.

Adim Victor
  • 104
  • 6
0

I have tried many of the solutions to this problem found on line, but in my case nothing worked except for reinstalling NVM for Windows (which I am using to manage multiple Node versions). In the installer, it detects installed Node versions and asks the user if they wish for NVM to control them. I said yes and NVM fixed all PATH issues. As a result, things worked as before. This issue may have multiple causes, but corrupted PATH is definitely one of them and (re)installing NVM fixes PATH.

Tomáš Hübelbauer
  • 9,179
  • 14
  • 63
  • 125
0

This is rather old question but this might be of some help for future reference. Delete node_modules folder and run npm install again. Worked for me.

Koder90
  • 19
  • 4
0

In my case , I edited my files on Linux where I had node v14.0.5 installed, when I rebooted to Windows where I had node v14.0.3 I got the same error. So I updated the node version on windows and all went fine for me.

Ace
  • 700
  • 7
  • 37
0

had similar issue.. i used yarn to fix it. i noticed that react-scripts was not found in my node modules so i decided to download it with npm but i seem to be failing too. so i tried yarn ( yarn add react-scripts) and that solved the nightmare! Hope this work for you as well. Happy debuging folks.

0

For me, I just re-installed the react-scripts instead of react-scripts --save.

0

Started getting this error in Azure DevOps yesterday out of nowhere when running npm run build:

'react-scripts' is not recognized as an internal or external command, operable program or batch file.

However when looking at npm ci that completed it was full of errors like:

FetchError: Invalid response body while trying to fetch https://registry.npmjs.org/@babel%2fcompat-data: ENOENT: no such file or directory, lstat 'D:\a\1.npm_cacache\content-v2\sha512\58\0b\dc7dce0b33e86d97736b3c419005951e32af28dda3f5b8c746f16d53d4baed1dc2fd2493e9310f744696008400bf8c91ca84f9fb3ebf541ba93a541b144a'

When commenting out the cache everything started working again:

npm_config_cache: $(Pipeline.Workspace)/.npm

- task: Cache@2
  inputs:
    key: 'npm | "$(Agent.OS)" | $(clientApp)\package-lock.json'
    restoreKeys: |
       npm | "$(Agent.OS)"
    path: $(npm_config_cache)
  displayName: Cache npm

The weird thing is that it has worked for over a year up until yesterday (2021-12-02) and we use the exact same code for caching as Microsoft has documented.

https://learn.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#nodejsnpm

Noting Degraded or Unhealthy on Azure DevOps Status

https://status.dev.azure.com/

isherwood
  • 58,414
  • 16
  • 114
  • 157
Ogglas
  • 62,132
  • 37
  • 328
  • 418
0

Here is what worked for me,

did npm install and that didn't fix it so I simply disabled windows defender firewall and then made a fresh cloning of the repo followed by npm start. That's it!

rashid_m
  • 11
  • 2
-1

I had the same problem and I tried the above thing, but that did not work some how. So, I just typed yarn. And it went.

Yash Patel
  • 39
  • 2
-2

When I make a new project using React, to install the React modules I have to run "npm install" (PowerShell) from within the new projects ClientApp folder (e.g. "C:\Users\Chris\source\repos\HelloWorld2\HelloWorld2\ClientApp"). The .NET core WebApp with React needs to have the React files installed in the correct location for React commands to work properly.

-2

This worked for me:

  • Go to the project folder in CLI and type npm install.Go for a similar command if using yarn etc.

  • Then type npm start if you are using Npm. Go for a similar command if using yarn etc.

  • The file starts working