尝试朗读npm start命令时出错

时间:2020-08-23 13:26:42

标签: reactjs npm cmd node-modules npm-start

我试图创建一个我先运行npx create-react-app my-app然后运行cd my-app的react项目,但是当我运行npm start时 已显示此错误:

> my-app@0.1.0 start C:\Users\USER\my-app
> react-scripts start

i 「wds」: Project is running at http://192.168.137.1/
i 「wds」: webpack output is served from
i 「wds」: Content not from webpack is served from C:\Users\HAMOOD\my-app\public
i 「wds」: 404s will fallback to /
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-app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-app@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\HAMOOD\AppData\Roaming\npm-cache\_logs\2020-08-23T13_09_04_330Z-debug.log

我试图删除node_modules,然后再次安装它,但是仍然存在相同的问题

3 个答案:

答案 0 :(得分:10)

我找到了一些可能的解决方案。似乎您正在使用Powershell,请首先检查您的Powershell是否为%SystemRoot%/ system32 / WindowsPowerShell / v1.0。之后,以管理员身份打开powershell并编写

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force

如果powershell存在问题,它应该会有所帮助。或者,有时在cra dev服务器尝试打开W​​eb浏览器时可能是错误。 github上有人说这对他有帮助:

此错误源于CRA尝试打开浏览器的事实: 为了跳过打开浏览器,添加 BROWSER=none 到您的.env或.env.local文件

另一种方法是使用这些命令降级项目的反应脚本

npm install react-scripts@2.1.8
npm start

答案 1 :(得分:2)

转到>控制面板\系统和安全性\系统\高级系统设置\环境变量,然后设置系统变量路径C:\ Windows \ System32 \变量,然后重新启动系统。

答案 2 :(得分:2)

1-首先,您需要编辑系统环境变量并找到Windows Poweshell所在的位置,以便在“系统环境变量路径”中添加新内容

Add Window Powershell path in system environment variable path

2-然后以管理员身份打开Window PoweShell并编写以下两个命令:

:)升级Window PowerShell是因为您的nodejs和npm已更新,但是powershell尚未更新,因此它与您的npm start或expo start发生冲突,因此您需要升级Windows powershell

Upgrade Window PowerShell because your nodejs and npm is updated but powershell is not updated so its making conflict with your npm start or expo start,so you should need to upgrade windows powershell.

然后运行Cmd并同时运行您的项目npm start或expo start,它会很快起作用!

enter image description here

运气最佳!