“npx create-react-app appname”不起作用
Posted
技术标签:
【中文标题】“npx create-react-app appname”不起作用【英文标题】:“npx create-react-app appname” not working 【发布时间】:2021-03-05 21:38:59 【问题描述】:当我运行 npx create-react-app appname
时,我收到以下错误消息:
You are running `create-react-app` 4.0.0, which is behind the latest release (4.0.1).
We no longer support global installation of Create React App.
Please remove any global installs with one of the following commands:
- npm uninstall -g create-react-app
- yarn global remove create-react-app
The latest instructions for creating a new app can be found here:
https://create-react-app.dev/docs/getting-started/
npm ERR! code 1
npm ERR! path /Users/hat/Projects/youtube/react
npm ERR! command failed
npm ERR! command sh -c create-react-app loll
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/hat/.npm/_logs/2020-11-23T06_53_20_858Z-debug.log
然后我运行npm uninstall -g create-react-app
并得到以下输出:
up to date in 380ms
found 0 vulnerabilities
运行npm uninstall -g create-react-app
命令后,我运行npx create-react-app appname
并收到与上述相同的错误消息。
这是位于/Users/hat/.npm/_logs/2020-11-23T06_53_20_858Z-debug.log
中的错误日志的样子:
0 verbose cli [
0 verbose cli '/Users/hat/.nvm/versions/node/v15.2.1/bin/node',
0 verbose cli '/Users/hat/.nvm/versions/node/v15.2.1/lib/node_modules/npm/bin/npm-cli.js',
0 verbose cli 'exec',
0 verbose cli '--',
0 verbose cli 'create-react-app',
0 verbose cli 'loll'
0 verbose cli ]
1 info using npm@7.0.8
2 info using node@v15.2.1
3 timing config:load:defaults Completed in 2ms
4 timing config:load:file:/Users/hat/.nvm/versions/node/v15.2.1/lib/node_modules/npm/npmrc Completed in 1ms
5 timing config:load:builtin Completed in 1ms
6 timing config:load:cli Completed in 1ms
7 timing config:load:env Completed in 1ms
8 timing config:load:file:/Users/hat/Projects/youtube/.npmrc Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:/Users/hat/.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:/Users/hat/.nvm/versions/node/v15.2.1/etc/npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:setUserAgent Completed in 0ms
17 timing config:load:setEnvs Completed in 1ms
18 timing config:load Completed in 8ms
19 verbose npm-session ccfcf510fa3376be
20 timing npm:load Completed in 17ms
21 http fetch GET 304 https://registry.npmjs.org/create-react-app 252ms (from cache)
22 timing arborist:ctor Completed in 1ms
23 timing arborist:ctor Completed in 0ms
24 timing arborist:ctor Completed in 0ms
25 timing command:exec Completed in 1728ms
26 verbose stack Error: command failed
26 verbose stack at ChildProcess.<anonymous> (/Users/hat/.nvm/versions/node/v15.2.1/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/index.js:64:27)
26 verbose stack at ChildProcess.emit (node:events:329:20)
26 verbose stack at maybeClose (node:internal/child_process:1055:16)
26 verbose stack at Process.ChildProcess._handle.onexit (node:internal/child_process:288:5)
27 verbose cwd /Users/hat/Projects/youtube
28 verbose Darwin 19.6.0
29 verbose argv "/Users/hat/.nvm/versions/node/v15.2.1/bin/node" "/Users/hat/.nvm/versions/node/v15.2.1/lib/node_modules/npm/bin/npm-cli.js" "exec" "--" "create-react-app" "loll"
30 verbose node v15.2.1
31 verbose npm v7.0.8
32 error code 1
33 error path /Users/hat/Projects/youtube
34 error command failed
35 error command sh -c create-react-app loll
36 verbose exit 1
我运行npm cache clean --force
来清除缓存。运行此命令后的输出为npm WARN using --force Recommended protections disabled.
我在跑步
节点版本:v15.2.1 npm 版本:7.0.8 npx 版本:7.0.8 操作系统:maOS CAtalina 10.15.7 我使用 vvm 版本 0.35.3 来管理我的节点版本我还注意到,当我将节点版本降级到 v14.1.0
时,npm
和 npx
会自动降级到 6.14.6。然后我运行npx create-react-app appname
并且命令有效。我能够创建反应应用程序。
节点 v15.2.1 是否存在错误?只是没有意义
【问题讨论】:
尝试以相同的顺序运行 npm init npm install create-react-app npx create-react-app myapp 【参考方案1】:我遇到了这个问题。显然,不再支持“create-react-app”的全局安装。所以我所做的是:'npm install create-react-app' 而不是 'npm install -g create-react-app'。然后 npx create-react-app 工作了。
【讨论】:
这对我来说非常有效,因为我已经运行了所有命令并且仍然遇到不同的错误。但是当我运行 'npm install create-react-app 而不添加 -g 标志时。然后 npx create-react-app 为我工作 很高兴我能帮上忙 :-)【参考方案2】:我也有同样的问题。 我用
修复了它npm install -g create-react-app
在那之后 npx create-react-app 工作了。
【讨论】:
【参考方案3】:所以,基本上我只是运行这个命令:: npm install -g create-react-app 而不是“npm install create-react-app”。 然后: npx create-react-app app_name 祝你好运!!
【讨论】:
以上是关于“npx create-react-app appname”不起作用的主要内容,如果未能解决你的问题,请参考以下文章
错误“您的缓存文件夹包含根拥有的文件,由于以前版本的 npm 中的错误”而“npx create-react-app example_app”