【发布时间】:2020-06-24 05:16:32
【问题描述】:
所以我决定按照教程学习 react。根据我输入的教程:
npm install -g create-react-app@1.5.2
然后我输入:
create-react-app my-app
运行后我输入:
npm start
它抛出了一些错误(我不记得究竟是什么错误。但它类似于 package.json 不包含npm start,也没有包含任何模板)
经过快速谷歌搜索后,我发现不再推荐以前的过程。
根据指南找到here
如果您之前通过
npm install -g create-react-app全局安装了create-react-app,我们建议您卸载该软件包 使用npm uninstall -g create-react-app确保npx始终 使用最新版本。
所以我在 cmd 中输入了npm uninstall -g create-react-app。卸载后我关闭了cmd并删除了运行npm install -g create-react-app后创建的文件夹
然后在 cmd 中输入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 提到尝试不同的方法。
【问题讨论】:
-
如果你看到我的问题,你会看到我按照官方文档,问题仍然存在。
标签: node.js reactjs npm create-react-app