[英]"'npm' is not recognized as an internal or external command" on create-react-app
[英]create-react-app + npm start - 'react-scripts' is not recognized as an internal or external command
我试过的类似问题
“'react-scripts' 不被识别为内部或外部命令”
我正在尝试通过 create-react-app cli 创建一个 React 项目,但在创建项目后出现错误
'react-scripts' is not recognized as an internal or external command, operable program or batch file"
当我尝试通过 npm start 启动开发服务器时。
我尝试过的:
1) 确保安装了 Node 和 npm 并且是最新的。 从我运行的项目目录(通过 powershell)
> npm -v
6.7.0
> node -v
v11.11.0
2)确保'react-scripts'在package.json中列出了正确的版本号
"name": "clipd2",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-scripts": "^2.1.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}...
3) 删除 node_modules 文件夹和 package-lock.json 并重新安装 npm 包
rm -r -fo node_modules
rm package-lock.json
npm install
npm install -S react-scripts
安装后,在 node_modules 中找到(并填充)react-scripts 目录
4) 确保 npm 在环境 PATH 变量中
> echo $Env:Path
....C:\Users\notMyUsername\AppData\Roaming\npm
我对下一步感到茫然。 奇怪的是,我在同一个父目录中有另一个 React 应用程序
clipdReact
clipd
clipd2
并且在 clipd 项目中使用 npm start 时没有问题(而失败的项目是 clipd2)
任何建议或提示将不胜感激!
**更新
此错误已提交但仍处于打开状态react-scripts 无法识别
您可以使用以下命令启动开发服务器(从您的项目目录中)
.\node_modules\.bin\react-scripts start
使用类似于上面的命令生成生产版本时要小心 - 我在尝试这样做时遇到了 babel 和 polyfills 的问题。
最后对我有用的是将脚本外壳设置为 powershell。 该命令是npm config set script-shell powershell
和npm config delete script-shell
以重置配置。 我不确定为什么会这样,我的猜测是因为node_modules\\.bin
中总是有 3 个脚本文件,不知何故,错误的 shell 被用于错误的脚本或类似的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.