安装了一个模块后,create-react-app 无法运行

4
我使用命令create-react-app qiyujidemo创建了一个React应用程序。我已经安装并成功运行了该应用程序。然后,我使用npm install weui@1.1.0 react-weui --save安装了一个模块。在安装完该模块后,我输入npm start,但是出现了错误。

qiyujidemo@0.1.0 start /Users/yianwork/wechat/qiyujidemo
react-scripts start
sh: react-scripts: command not found
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! qiyujidemo@0.1.0 start: react-scripts start
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the qiyujidemo@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/yianwork/.npm/_logs/2017-08-07T08_41_16_944Z-debug.log

我复制了日志文件/Users/yianwork/.npm/_logs/2017-08-07T08_41_16_944Z-debug.log。
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/Cellar/node/8.1.0_1/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'start' ]
2 info using npm@5.0.3
3 info using node@v8.1.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle qiyujidemo@0.1.0~prestart: qiyujidemo@0.1.0
6 silly lifecycle qiyujidemo@0.1.0~prestart: no script for prestart, continuing
7 info lifecycle qiyujidemo@0.1.0~start: qiyujidemo@0.1.0
8 verbose lifecycle qiyujidemo@0.1.0~start: unsafe-perm in lifecycle true
9 verbose lifecycle qiyujidemo@0.1.0~start: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/yianwork/wechat/qiyujidemo/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/yianwork/Library/Android/sdk/tools:/Users/yianwork/Library/Android/sdk/platform-tools
10 verbose lifecycle qiyujidemo@0.1.0~start: CWD: /Users/yianwork/wechat/qiyujidemo
11 silly lifecycle qiyujidemo@0.1.0~start: Args: [ '-c', 'react-scripts start' ]
12 info lifecycle qiyujidemo@0.1.0~start: Failed to exec start script
13 verbose stack Error: qiyujidemo@0.1.0 start: `react-scripts start`
13 verbose stack spawn ENOENT
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:33:16)
13 verbose stack     at emitTwo (events.js:125:13)
13 verbose stack     at ChildProcess.emit (events.js:213:7)
13 verbose stack     at maybeClose (internal/child_process.js:887:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:208:5)
14 verbose pkgid qiyujidemo@0.1.0
15 verbose cwd /Users/yianwork/wechat/qiyujidemo
16 verbose Darwin 16.4.0
17 verbose argv "/usr/local/Cellar/node/8.1.0_1/bin/node" "/usr/local/bin/npm" "start"
18 verbose node v8.1.0
19 verbose npm  v5.0.3
20 error file sh
21 error code ELIFECYCLE
22 error errno ENOENT
23 error syscall spawn
24 error qiyujidemo@0.1.0 start: `react-scripts start`
24 error spawn ENOENT
25 error Failed at the qiyujidemo@0.1.0 start script.
25 error This is probably not a problem with npm. There is likely additional logging output above.
26 verbose exit [ 1, true ]

我输入了yarn start,然后出现以下错误:

yians-iMac:qiyujidemo yianwork$ yarn start
yarn start v0.24.5
$ react-scripts start
sh: react-scripts: command not found
error Command failed with exit code 127.

谁能解决这个问题?出了什么问题?

我通过create-react-app创建了一个新项目。它可以正常运行。然后我安装了React-router,但是出现了同样的问题。我卸载了react-weui,但它仍然无法运行。

当我在create-react-app演示中写入yarn add antd时,项目可以正常运行。 我必须使用yarn添加依赖吗?


你是否全局安装了create-react-app?你清理过node_modules文件夹吗?https://dev59.com/ylkR5IYBdhLWcg3w_B5d - Nevosis
@Nevosis 我可以在每个文件夹中使用 create-react-app,所以我认为我应该全局安装 create-react-app。我删除了 node_modules 并重新安装,但项目仍无法运行。 - jiexishede
@jiexishede 你是否在正确的目录路径下编写命令?比如在你的项目文件夹内。在执行 create-react-app myApp 后,进入你的应用程序文件夹 cd myApp,然后进行所有的 npm 操作。 - Fawaz
@Fawaz 我保证我在正确的目录路径下编写了命令,因为我可以运行 npm start 命令。 - jiexishede
2
@jiexishede 还有报道称,npm v5存在问题,请参考此链接 https://dev59.com/M6Pia4cB1Zd3GeqPsxFI?rq=1 进行降级并检查是否可以按照链接中的建议解决问题。 - Fawaz
显示剩余2条评论
1个回答

0
你的 package.json 文件中是否有 react-scripts?如果没有,请安装它并将以下内容添加到你的 package.json 文件中:
"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "predeploy": "npm run build && cp CNAME build/CNAME",
    "deploy": "gh-pages -d build"
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接