![](/img/trans.png)
[英]npx create-react-app command does not work, returns ES module error instead
[英]npx create-react-app command returns error
所以我決定按照教程學習反應。 根據我輸入的教程:
npm install -g create-react-app@1.5.2
然后我輸入:
create-react-app my-app
運行后我輸入:
npm start
它引發了一些錯誤(我不記得究竟是什么錯誤。但它類似於 package.json 不包括npm start
后快速搜索我發現沒有包含任何以前的模板)不再推薦過程。 根據在這里找到的指南
如果您之前通過
npm install -g create-react-app
create-react-app
全局安裝了 create-react-app ,我們建議您使用npm uninstall -g create-react-app
package 以確保npx
始終使用最新版本的 create-react-app。
所以我在 cmd 中輸入npm uninstall -g create-react-app
。 卸載后我關閉了 cmd 並刪除了運行npm install -g create-react-app
后創建的文件夾
然后在 cmd 中鍵入 npx npx create-react-app my-app
后。 但它返回此錯誤:
npm ERR! code ENOLOCAL
npm ERR! Could not install from "Amin\AppData\Roaming\npm-cache\_npx\4996" as it does not contain a package.json file.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Farhan Bin Amin\AppData\Roaming\npm-cache\_logs\2020-06-24T04_44_56_925Z-debug.log
Install for [ 'create-react-app@latest' ] failed with code 1
調試日志包括在下面:
0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'install',
1 verbose cli 'create-react-app@latest',
1 verbose cli '--global',
1 verbose cli '--prefix',
1 verbose cli 'C:\\Users\\Farhan',
1 verbose cli 'Bin',
1 verbose cli 'Amin\\AppData\\Roaming\\npm-cache\\_npx\\4996',
1 verbose cli '--loglevel',
1 verbose cli 'error',
1 verbose cli '--json'
1 verbose cli ]
2 info using npm@6.14.4
3 info using node@v12.16.3
4 verbose npm-session 0eec5b00126c667b
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 silly fetchPackageMetaData error for file:Amin\AppData\Roaming\npm-cache\_npx\4996 Could not install from "Amin\AppData\Roaming\npm-cache\_npx\4996" as it does not contain a package.json file.
8 http fetch GET 404 https://registry.npmjs.org/Bin 124ms
9 http fetch GET 304 https://registry.npmjs.org/create-react-app 178ms (from cache)
10 http fetch GET 404 https://registry.npmjs.org/Bin 39ms
11 silly fetchPackageMetaData error for Bin@latest 404 Not Found - GET https://registry.npmjs.org/Bin - Not found
12 silly pacote tag manifest for create-react-app@latest fetched in 193ms
13 timing stage:rollbackFailedOptional Completed in 0ms
14 timing stage:runTopLevelLifecycles Completed in 201ms
15 verbose stack Error: ENOENT: no such file or directory, open 'F:\react\Amin\AppData\Roaming\npm-cache\_npx\4996\package.json'
16 verbose cwd F:\react
17 verbose Windows_NT 10.0.15063
18 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "create-react-app@latest" "--global" "--prefix" "C:\\Users\\Farhan" "Bin" "Amin\\AppData\\Roaming\\npm-cache\\_npx\\4996" "--loglevel" "error" "--json"
19 verbose node v12.16.3
20 verbose npm v6.14.4
21 error code ENOLOCAL
22 error Could not install from "Amin\AppData\Roaming\npm-cache\_npx\4996" as it does not contain a package.json file.
23 verbose exit [ 1, true ]
我用谷歌搜索了幾個小時,但似乎沒有任何東西可以解決這個問題。
更新:所以似乎只有yarn create react-app my-app
有效。 但 npm/npx 不是。 感謝@prisar 提到嘗試不同的方法。
嘗試使用npm
或yarn
代替。 npx緩存似乎有問題。 一次,嘗試清除緩存。
我認為最好的參考是官方指南建議,
您需要在您的機器上安裝 Node >= 8.10 和 npm >= 5.6
所以在確保需求后,嘗試卸載全局 create-react-app 並運行 npx 代替。
npx create-react-app my-app
我認為本教程使用的是舊的安裝 CRA,我可能錯了。
我之前也有這個問題。 嘗試從根文件夾中刪除 node_modules、package-lock.json 文件並運行
npm 緩存清理 --force && npm 安裝
接着-
npx 創建反應應用程序我的應用程序
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.