React scripts与nodemon并发运行失败,执行npm start报错求助
npm start with concurrently Setup Hey there, let’s work through this npm start error you’re facing with your concurrently script. I’ve dealt with similar issues before, so here’s a step-by-step breakdown of the most likely fixes:
1. Verify Dependencies Are Installed Locally
First, make sure concurrently and nodemon are installed as dev dependencies in your project—global installs can sometimes cause path issues. Run this command to install them:
npm install concurrently nodemon --save-dev
Double-check your package.json to confirm they appear under devDependencies.
2. Fix Script Quoting for Your OS
Quotation mark handling varies between Windows and Unix-based systems (Mac/Linux), which is a common source of errors with concurrently:
- For Mac/Linux: Stick with double quotes around the entire script, and single quotes around each command:
"start": "concurrently 'nodemon server' 'react-scripts start'" - For Windows: Use double quotes around each command, and escape the inner quotes with backslashes:
Alternatively, you can use"start": "concurrently \"nodemon server\" \"react-scripts start\""cross-envto normalize behavior across systems, but adjusting quotes usually suffices.
3. Confirm the Server File Path is Correct
Make sure nodemon server points to your actual server entry file. If your server is in server.js at the root, this works—but if it’s in a subfolder (like server/index.js), update the command to:
"start": "concurrently \"nodemon server/index.js\" \"react-scripts start\""
Test running nodemon server alone first to confirm it finds the file and starts without errors.
4. Check for Port Conflicts
React’s react-scripts start defaults to port 3000. If your server is also configured to use 3000, you’ll get a port conflict error. Fix this by:
- Changing your server’s port to something else (e.g., 5000) in your server code.
- Or, modifying the React start command to use a different port:
- Mac/Linux:
"start": "concurrently \"nodemon server\" \"PORT=3001 react-scripts start\"" - Windows:
"start": "concurrently \"nodemon server\" \"set PORT=3001 && react-scripts start\"" - You can also create a
.envfile in your project root withPORT=3001to set the React port permanently.
- Mac/Linux:
5. Test Services Separately
Isolate the issue by running each service individually first:
- Add separate scripts to your
package.json:"server": "nodemon server", "client": "react-scripts start" - Run
npm run server—if this fails, the problem is with your backend setup, notconcurrently. - Run
npm run client—if this fails, troubleshoot your React app (e.g., missing dependencies, corrupted node_modules).
Only when both services run smoothly should you test the concurrently script again.
6. Check Package Version Compatibility
Occasionally, newer versions of concurrently, nodemon, or react-scripts can have compatibility bugs. Try pinning concurrently to a stable version (like 7.6.0, which works well with most setups):
npm install concurrently@7.6.0 --save-dev
内容的提问来源于stack exchange,提问作者shankar

