iT邦幫忙

0

react 建立好新專案,但執行npm start時出現錯誤

react 建立好新專案,但執行npm start時出現錯誤

錯誤訊息為:

Windows PowerShell
Copyright (C) Microsoft Corporation. 著作權所有,並保留一切權利。

Starting the development server...

events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: spawn powershell ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)     
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {   
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn powershell',
  path: 'powershell',
  spawnargs: [
    '-NoProfile',
    '-NonInteractive',
    '–ExecutionPolicy',
    'Bypass',
    '-EncodedCommand',
  ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hello@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hello@0.1.0 start script.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\jbuduoo\AppData\Roaming\npm-cache\_logs\2020-08-31T04_01_08_818Z-debug.log
PS D:\abc\hello\hello> sodu npm satart
sodu : 無法辨識 'sodu' 詞彙是否為 Cmdlet、函數、指令檔或可執行程式的名稱。請檢查名稱拼字是否正確,如果包含路徑  
的話,請確認路徑是否正確,然後再試一次。
位於 線路:1 字元:1
+ sodu npm satart
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (sodu:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
PS D:\abc\hello\hello> npm run
Lifecycle scripts included in hello:
  start
    react-scripts start
  test
    react-scripts test

available via `npm run-script`:
Starting the development server...

events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: spawn powershell ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)     
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {   
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn powershell',
  path: 'powershell',
  spawnargs: [
    '-NoProfile',
    '-NonInteractive',
    '–ExecutionPolicy',
    'Bypass',
    '-EncodedCommand',
  ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
Starting the development server...

events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: spawn powershell ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)     
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {   
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn powershell',
  path: 'powershell',
  spawnargs: [
    '-NoProfile',
    '-NonInteractive',
    '–ExecutionPolicy',
    'Bypass',
    '-EncodedCommand',
    'UwB0AGEAcgB0ACAAIgBgACIAaAB0AHQAcAA6AC8ALwBsAG8AYwBhAGwAaABvAHMAdAA6ADMAMAAwADAAYAAiACIA'
  ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! hello@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the hello@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!     C:\Users\jbuduoo\AppData\Roaming\npm-cache\_logs\2020-08-31T04_03_18_678Z-debug.log

log的訊息是

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   'start'
1 verbose cli ]
2 info using npm@6.14.6
3 info using node@v12.18.3
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle hello@0.1.0~prestart: hello@0.1.0
6 info lifecycle hello@0.1.0~start: hello@0.1.0
7 verbose lifecycle hello@0.1.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle hello@0.1.0~start: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\abc\hello\hello\node_modules\.bin;D:\Java\jdk-11.0.2;C:\Syscom\java\spring-2.2.6.RELEASE\bin;D:\Software\Maven\apache-maven-3.6.3\bin;C:\Users\jbuduoo\Python\Python36;D:\Java\jdk-11.0.2\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\nodejs\;C:\Syscom\java\spring-2.3.3.BUILD-SNAPSHOT\bin;C:\Microsoft VS Code\bin;D:\GoogleCloud\google-cloud-sdk\bin;C:\Users\jbuduoo\AppData\Local\GitHubDesktop\bin;C:\Users\jbuduoo\AppData\Roaming\npm
9 verbose lifecycle hello@0.1.0~start: CWD: D:\abc\hello\hello
10 silly lifecycle hello@0.1.0~start: Args: [ '/d /s /c', 'react-scripts start' ]
11 silly lifecycle hello@0.1.0~start: Returned: code: 1  signal: null
12 info lifecycle hello@0.1.0~start: Failed to exec start script
13 verbose stack Error: hello@0.1.0 start: `react-scripts start`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid hello@0.1.0
15 verbose cwd D:\abc\hello\hello
16 verbose Windows_NT 10.0.18362
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "start"
18 verbose node v12.18.3
19 verbose npm  v6.14.6
20 error code ELIFECYCLE
21 error errno 1
22 error hello@0.1.0 start: `react-scripts start`
22 error Exit status 1
23 error Failed at the hello@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 ]

環境重新設置了,但找了好久找不出解決方式,我用管理者模式登錄進去也不行,可否請大神支援一下。

看更多先前的討論...收起先前的討論...
jbuduoo iT邦新手 4 級 ‧ 2020-08-31 13:03:15 檢舉
那個Log的位置也怪怪的,是有什麼地方設定錯誤嗎?
通靈亡 iT邦高手 1 級 ‧ 2020-08-31 13:24:09 檢舉
https://github.com/facebook/create-react-app/issues/7061
fillano iT邦超人 1 級 ‧ 2020-08-31 16:51:44 檢舉
windows底下應該沒有sodu這個命令(而且你可能也打錯,恐怕應該是sudo),你直接npm start看看
jbuduoo iT邦新手 4 級 ‧ 2020-08-31 17:10:44 檢舉
直接執行,就是以下的錯誤
```
PS D:\abc\my-app4> npm start

> my-app4@0.1.0 start D:\abc\my-app4
> react-scripts start
Starting the development server...

events.js:292
throw er; // Unhandled 'error' event
^

Error: spawn powershell ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'ENOENT',
code: 'ENOENT',
syscall: 'spawn powershell',
path: 'powershell',
spawnargs: [
'-NoProfile',
'-NonInteractive',
'–ExecutionPolicy',
'Bypass',
'-EncodedCommand',
'UwB0AGEAcgB0ACAAIgBgACIAaAB0AHQAcAA6AC8ALwBsAG8AYwBhAGwAaABvAHMAdAA6ADMAMAAwADAAYAAiACIA'
]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-app4@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-app4@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! C:\Users\jbuduoo\AppData\Roaming\npm-cache\_logs\2020-08-31T09_09_26_217Z-debug.log
```
npm install 再 npm start 看看
fillano iT邦超人 1 級 ‧ 2020-08-31 22:05:16 檢舉
不然試試:
https://stackoverflow.com/questions/42308879/how-to-solve-npm-error-npm-err-code-elifecycle
jbuduoo iT邦新手 4 級 ‧ 2020-09-01 20:37:13 檢舉
以下是解法,但我試過都不行,所以就重湩了,還好成功了。

系統屬性/環境變量,添加C:\ Windows \ System32的新條目。

npm install -g npm@latest 更新npm,因為有時會出現問題。
rm -rf node_modules/ && npm cache clean

node_modules 或在node_modules資料夾按Shift +Delete

npm install

npm start
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答