Mac M1芯片VSCode中React项目执行npm start报错:缺失start脚本
解决M1 Mac上VSCode运行React项目时npm start提示"Missing script: 'start'"的问题
报错信息
执行npm start时出现如下错误:
react-app % npm start npm ERR! Missing script: "start" npm ERR! npm ERR! Did you mean one of these? npm ERR! npm star # Mark your favorite packages npm ERR! npm stars # View packages marked as favorites npm ERR! npm ERR! To see a list of scripts, run: npm ERR! npm run
日志路径:
npm ERR! A complete log of this run can be found in: /Users/name/.npm/_logs/2023-07-17T13_47_56_576Z-debug-0.log
项目package.json内容
{ "name": "my-project", "version": "0.1.0", "private": true, "dependencies": { "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-scripts": "5.0.1", "web-vitals": "^2.1.4" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, "eslintConfig": { "extends": [ "react-app", "react-app/jest" ] }, "browserslist": { "production": [ ">0.2%", "not dead", "not op_mini all" ], "development": [ "last 1 chrome version", "last 1 firefox version", "last 1 safari version" ] } }
解决方法
确认终端路径是否正确
报错显示当前路径是react-app,但你的项目根目录是my-project,执行cd my-project切换到正确的项目根目录后,再重新运行npm start。重置依赖包
- 执行
rm -rf node_modules package-lock.json - 执行
npm install重新安装所有依赖 - 再次运行
npm start
- 执行
清空npm缓存
执行npm cache clean --force清空缓存,之后重新安装依赖并启动项目。检查react-scripts安装状态
执行npm list react-scripts查看该包是否存在,若不存在,手动安装:npm install react-scripts@5.0.1 --saveM1芯片适配处理
若上述方法无效,尝试用Rosetta 2运行终端:- 找到「终端」应用,右键选择「显示简介」
- 勾选「使用Rosetta打开」
- 重启终端,进入项目目录重新执行
npm start
内容的提问来源于stack exchange,提问作者Erza Roxx
相关产品推荐
相关产品推荐

