![](/img/trans.png)
[英]"'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.