📌  相关文章
📜  > client@0.1.0 start > react-scripts start sh: react-scripts: command not found - TypeScript (1)

📅  最后修改于: 2023-12-03 14:38:44.983000             🧑  作者: Mango

Introduction to React App Initialization Error

If you are a developer trying to start a React app and encountered an error that looks like this:

> client@0.1.0 start > react-scripts start sh: react-scripts: command not found - TypeScript

Don't worry, we will go through the possible causes and solutions for this error.

Possible Causes
  1. react-scripts is not installed
  2. react-scripts is installed locally but not globally, and the script is tried to be run globally
  3. npm or yarn version is outdated
  4. node_modules folder is corrupted
Solutions
1. Install react-scripts

The first and simplest solution is to install react-scripts globally. Make sure you have npm or yarn installed and run the following command:

npm install -g react-scripts

or

yarn global add react-scripts

This will install react-scripts globally, which may take a few minutes depending on your internet speed.

2. Run start script locally

If you have already installed react-scripts locally in your project, you can try to run the start script from your local node_modules.

npm start

or

yarn start

This will run the start script from the react-scripts in your local node_modules.

3. Update npm or yarn

If you have an outdated version of npm or yarn, it may cause errors in installing or running packages. To update npm, run the following command:

npm install -g npm

To update yarn, run:

npm install -g yarn
4. Delete node_modules folder

If none of the above solutions work, you can try to delete the node_modules folder and reinstall all the packages.

rm -rf node_modules
npm install

or

rm -rf node_modules
yarn

This will delete the current node_modules folder and reinstall all the packages. This may take some time depending on the number of packages you have in your project.

Conclusion

There can be several reasons why the react-scripts command is not found. Make sure to check if react-scripts is installed, if the script is tried to be run globally when it is installed locally, if the npm or yarn version is outdated, or if the node_modules folder is corrupted. With the solutions mentioned above, you should be able to resolve the issue and start your React app.