安装Redux后react-scripts丢失,Create React App项目运行异常求助
Hey there, let's figure out what went wrong and get your project back up and running quickly.
What Caused the Problem
The react-redux@5.0.7 version you installed is extremely outdated—this release dates back to 2018, and it’s incompatible with the modern React dependencies that come with a fresh Create React App project. When your package manager (npm/yarn) tried to satisfy this old version’s requirements, it had to remove over 1000 existing packages (including core dependencies for react-scripts) to resolve conflicts, which broke your project’s ability to run.
Step-by-Step Fix
Clean up the broken dependency state
- First, delete the
node_modulesfolder (this holds all your installed packages) and the lock file (package-lock.jsonfor npm,yarn.lockfor yarn). You can do this manually, or run these commands:# For npm users rm -rf node_modules package-lock.json # For yarn users rm -rf node_modules yarn.lock
- First, delete the
Install compatible versions of react-redux and redux
Skip specifying the old version number—install the latest stable versions that work with your Create React App setup:# npm npm install react-redux redux # yarn yarn add react-redux reduxYour package manager will automatically pick versions that play nice with your existing project dependencies, no more mass package deletions.
Restart your project
Run the start command like you normally would:npm start # or yarn startYour project should boot up without issues now.
Quick Tip for the Future
Unless you have a specific reason to use an old package version, always install the latest stable release by default. If you do need a specific version, double-check that it’s compatible with your project’s current React version first—this avoids messy dependency conflicts like the one you ran into.
内容的提问来源于stack exchange,提问作者Marek Hubáček

