簡體   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