繁体   English   中英

npm 启动失败:错误:启动:`react-scripts start`

[英]npm start failing: Error: start: `react-scripts start`

同事使用 create-react-app 创建了一个项目,它可以在他的计算机上运行。 我克隆,运行 npm 安装,然后 npm 启动,得到以下失败错误:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/usr/local/Cellar/node/15.8.0/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'start'
1 verbose cli ]
2 info using npm@6.14.8
3 info using node@v15.8.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle candyjar@0.1.0~prestart: candyjar@0.1.0
6 info lifecycle candyjar@0.1.0~start: candyjar@0.1.0
7 verbose lifecycle candyjar@0.1.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle candyjar@0.1.0~start: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/dzhai/Documents/workplace/tcoe-candyjar/apis/src/main/app/node_modules/.bin:/usr/local/opt/icu4c/sbin:/usr/local/opt/icu4c/bin:/usr/local/opt/gnu-getopt/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/dzhai/Library/Python/3.7/bin:/Library/Apple/usr/bin:/opt/apache-maven/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/dzhai/Library/Python/3.7/bin:/Library/Apple/usr/bin
9 verbose lifecycle candyjar@0.1.0~start: CWD: /Users/dzhai/Documents/workplace/tcoe-candyjar/apis/src/main/app
10 silly lifecycle candyjar@0.1.0~start: Args: [ '-c', 'react-scripts start' ]
11 silly lifecycle candyjar@0.1.0~start: Returned: code: 1  signal: null
12 info lifecycle candyjar@0.1.0~start: Failed to exec start script
13 verbose stack Error: candyjar@0.1.0 start: `react-scripts start`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (node:events:378:20)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (node:events:378:20)
13 verbose stack     at maybeClose (node:internal/child_process:1067:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)
14 verbose pkgid candyjar@0.1.0
15 verbose cwd /Users/dzhai/Documents/workplace/tcoe-candyjar/apis/src/main/app
16 verbose Darwin 19.6.0
17 verbose argv "/usr/local/Cellar/node/15.8.0/bin/node" "/usr/local/bin/npm" "start"
18 verbose node v15.8.0
19 verbose npm  v6.14.8
20 error code ELIFECYCLE
21 error errno 1
22 error candyjar@0.1.0 start: `react-scripts start`
22 error Exit status 1
23 error Failed at the candyjar@0.1.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

有人可以帮忙吗? 谢谢

PS:我已经尝试删除 node_modules 并重新运行 npm 安装、卸载/重新安装节点等。

发现这个线程https://github.com/facebook/create-react-app/issues/9594这似乎表明重新安装节点可以解决问题,但它对我不起作用。

跟进:通过额外的手动步骤完全删除节点,例如,这里建议https://stackabuse.com/how-to-uninstall-node-js-from-mac-osx/ ,然后重复该过程,然后得到一个错误日志略有不同:

23 verbose stack Error: command failed
23 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/index.js:64:27)
23 verbose stack     at ChildProcess.emit (node:events:378:20)
23 verbose stack     at maybeClose (node:internal/child_process:1067:16)
23 verbose stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)

折腾了两天终于弄明白,当前app是一个子子项目,位于这样的路径:main-project/sub-project1/src/main/sub-sub-project1。 但是在另一个同事过去工作的 sub-project1 文件夹中有一堆剩余的节点文件(package.json 等),显然我已经运行了“npm install”并在那里生成了一个 node_modules/ 文件夹,因为它是 gitignored,我从来没有意识到这一点。 这个 node_modules/ 文件夹是导致节点命令在 sub-sub-project1 文件夹中运行时造成混淆的原因,其中存在另一个 node_modules/。

综上所述,这种线性分层的方式不要有多个节点项目,可能会导致节点命令混乱。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM