react-scripts: command not found

2020-06-09 04:14发布

I am currently trying to use create-react-app which uses three different packages: react, react-scripts and react-dom. I have installed create-react-app and then when I change into the directory and hit npm start I get a react-scripts: command not found. I've ran into a lot of problems with this. I can see react-scripts is in my node_modules folder but I keep getting command not found when trying to run npm start. I tried to delete and re-install all of my node_modules but it didn't work. Anyone else having this issue?

 ✘ ✝  Node/toDoApp/my-test   master±  npm start

> my-test@0.1.0 start /Users/jzilch/Desktop/Web 
Projects/Node:Express/Node/toDoApp/my-test
> react-scripts start

sh: react-scripts: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! my-test@0.1.0 start: `react-scripts start`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the my-test@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely 
additional logging output above.

标签: reactjs
8条回答
放荡不羁爱自由
2楼-- · 2020-06-09 04:34

I fixed it by changing folder name in my local system, from

new/landing

to

new_landing

However, the git branch name remains like "new/landing". This was the case with my MAC system.

查看更多
霸刀☆藐视天下
3楼-- · 2020-06-09 04:41

i too faced this problem once .to solve this ,delete your

node_modules
yarn.lock
manifest_lock.json

it works .

查看更多
叼着烟拽天下
4楼-- · 2020-06-09 04:42

Firstly Delete package-lock.json file in your project folder.

And then install dependencies again by npm install. That should solve this issue.

查看更多
时光不老,我们不散
5楼-- · 2020-06-09 04:48

As I was using yarn, I had to run yarn add react-scripts.

查看更多
戒情不戒烟
6楼-- · 2020-06-09 04:49

This usually happens because of a bad npm packages installation (using npm and yarn at the same time?). It can be desperating, but if you try these steps, it should work.

1st solution:

Remove node_modules folder. At the project's root folder, run

> yarn
> yarn run start

2nd solution:

At the project's root folder, run

> yarn upgrade
> yarn
> yarn run start

Next time you want to add a dependency using create-react-app, I recommend you to use 'yarn add' instead of 'npm install'. (Source: https://github.com/facebook/create-react-app/issues/1155)

查看更多
够拽才男人
7楼-- · 2020-06-09 04:54

I had this problem for ages and I eventually found my solution by sheer chance.
Turns out, you can't have spaces in any folder names.

e.g. ~/projects/tutorial/ReactJS/JavaScript Framework: ReactJS/app-name won't work because JavaScript Framework: ReactJS contains spaces.
In general, it's probably not great practice to be using spaces in folder/file names anyway but I hope this saves someone at least 4 hours of trial and error.

I would recommend removing the : from your folder names too! (just to be safe)

查看更多
登录 后发表回答