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

运行React项目时出现报错,请求协助修复

React项目运行错误的常见解决办法
  • 清理依赖重装
    先删掉本地依赖包和锁文件,重新安装:
    rm -rf node_modules package-lock.json yarn.lock
    npm install
    
  • 解决端口占用问题
    要是默认3000端口被占,要么改启动端口:
    在package.json的scripts里改成:
    "start": "PORT=3001 react-scripts start"
    
    要么直接杀掉占用端口的进程:
    # Mac/Linux系统
    lsof -ti:3000 | xargs kill -9
    # Windows系统
    taskkill /F /PID $(netstat -ano | findstr :3000 | findstr LISTENING | awk '{print $5}')
    
  • 更新react-scripts
    很多启动错误是脚本版本兼容问题,更到最新稳定版:
    npm install react-scripts@latest
    
  • 检查Node.js版本
    React项目对Node版本有要求,比如React 18需要Node 14.0以上,用nvm切换合适版本:
    nvm use 16
    
  • 清空npm缓存
    缓存损坏也可能导致问题,强制清理:
    npm cache clean --force
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 12:54:28