📅  最后修改于: 2023-12-03 14:38:44.983000             🧑  作者: Mango
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.
react-scripts
is not installedreact-scripts
is installed locally but not globally, and the script is tried to be run globallynpm
or yarn
version is outdatednode_modules
folder is corruptedreact-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.
start
script locallyIf 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
.
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
node_modules
folderIf 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.
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.