You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React.js中执行npm start命令时遇到问题

Hey there! Let's troubleshoot that npm start error you're hitting after setting up your React app. I've dealt with this exact scenario dozens of times, so here are the most reliable fixes sorted by how likely they are to resolve the issue:

Fixes for npm start Error in React App
  • Clear Corrupted Dependencies & Cache
    This is my go-to first step when React scripts act up. Corrupted packages or cached data are super common culprits:

    1. Stop any running dev servers first
    2. Delete the node_modules folder and package-lock.json (or yarn.lock if you use Yarn) from your my-app directory
    3. Run npm cache clean --force to wipe npm's local cache
    4. Reinstall dependencies with npm install
    5. Try npm start again
  • Ditch Global create-react-app (Use npx Instead)
    The official React docs no longer recommend installing create-react-app globally—this often causes version conflicts between the global package and the latest React scripts. Let's fix this:

    1. Uninstall the global package: npm uninstall -g create-react-app
    2. Delete your existing my-app folder
    3. Create a new app with the official, up-to-date method: npx create-react-app my-app
    4. Cd into my-app and run npm start
  • Resolve Port Conflicts
    By default, npm start uses port 3000. If another app (like a local API, another dev server, or even a background tool) is using that port, you'll get an error. Here's how to fix it:

    • Quick fix: When the error prompts you to run on a different port, just type Y and hit enter
    • Manual port set: Modify the start script in package.json:
      • For macOS/Linux: Change "start": "react-scripts start" to "start": "PORT=3001 react-scripts start"
      • For Windows: Change it to "start": "set PORT=3001 && react-scripts start"
    • Kill the conflicting process: On macOS/Linux run lsof -ti:3000 | xargs kill -9; on Windows, open Task Manager, find the Node.js process using port 3000, and end it
  • Update Node.js & npm to Compatible Versions
    Outdated Node.js or npm versions often clash with React's latest scripts. Here's what to do:

    1. Check your current versions with node -v and npm -v
    2. React recommends Node.js 14.0.0+ and npm 5.6+. If yours are older:
    • Update Node.js to the latest stable version via your preferred package manager
    • Update npm with npm install -g npm@latest
  • Fix Global Permission Issues
    If you ran into errors during the global create-react-app install, you probably have permission problems. Avoid using sudo (it can mess up your npm setup long-term) — instead, stick with the npx method above (it skips global installs entirely) or configure npm to use a local directory for global packages.

内容的提问来源于stack exchange,提问作者abu abu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:43:42