简体   繁体   English

运行 npm 时无法解决错误

[英]I can't solve Error while running npm Start

I have an issue please.我有一个问题。 Each time I set up a react project, either with create react app or using webpack or whatever, I just get stuck at NPM start.每次我设置一个反应项目时,无论是使用创建反应应用程序还是使用 webpack 或其他任何东西,我都会卡在 NPM 开始。 It always returns an error.它总是返回一个错误。 Please I am fed up with this.请让我受够了这个。 Can someone tell me what the issue might be?有人可以告诉我可能是什么问题吗? But what bugs me the most is, I use Next.js, and each time I run Npm start on Nextjs dev server, it works fine... Please what might be the issue with my react app?但最让我烦恼的是,我使用 Next.js,每次我在 Nextjs 开发服务器上运行 Npm 启动时,它工作正常......请问我的反应应用程序可能有什么问题?

Here's the error:这是错误:

C:\Users\Kelly\Desktop\My webpack react app>npm start

> webpackreactapp@1.0.0 start C:\Users\Kelly\Desktop\My webpack react app
> webpack-dev-server --mode development --open --hot

i 「wds」: Project is running at http://localhost:8080/
i 「wds」: webpack output is served from /
i 「wds」: Content not from webpack is served from C:\Users\Kelly\Desktop\My webpack react app
events.js:298
      throw er; // Unhandled 'error' event
      ^

Error: spawn cmd ENOENT
←[90m    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)←[39m
←[90m    at onErrorNT (internal/child_process.js:467:16)←[39m
←[90m    at processTicksAndRejections (internal/process/task_queues.js:84:21)←[39m
Emitted 'error' event on ChildProcess instance at:
←[90m    at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)←[39m
←[90m    at onErrorNT (internal/child_process.js:467:16)←[39m
←[90m    at processTicksAndRejections (internal/process/task_queues.js:84:21)←[39m {
  errno: ←[33m-4058←[39m,
  code: ←[32m'ENOENT'←[39m,
  syscall: ←[32m'spawn cmd'←[39m,
  path: ←[32m'cmd'←[39m,
  spawnargs: [ ←[32m'/c'←[39m, ←[32m'start'←[39m, ←[32m'""'←[39m, ←[32m'/b'←[39m, ←[32m'http://localhost:8080/'←[39m ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! webpackreactapp@1.0.0 start: `webpack-dev-server --mode development --open --hot`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the webpackreactapp@1.0.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\Kelly\AppData\Roaming\npm-cache\_logs\2020-04-07T07_23_56_199Z-debug.log

Have you restored the npm packages?你恢复npm包了吗? In the terminal, run: npm install在终端中,运行: npm install

About this question I posted here earlier, I finally found a solution to it.关于我之前在这里发布的这个问题,我终于找到了解决方案。 And I hope it would help someone.我希望它会帮助某人。 I think it's probably due to my computer's OS, the fact is I still don't know the reason my NPM start didn't work, but I found out that it was because my "react-scripts" version, which can be found in your package.json, was 3.4.1, which I think is the latest.我认为这可能是由于我的计算机的操作系统,事实上我仍然不知道我的 NPM 启动不起作用的原因,但我发现这是因为我的“react-scripts”版本,可以在你的 package.json 是 3.4.1,我认为是最新的。 I tried downloading the lower versions up till 2.1.8, then it worked at version 2.1.8.我尝试下载较低版本直到 2.1.8,然后它在 2.1.8 版本上运行。 Though that version is way outdated, and it's probably not recommended that anyone use it, but if you still are stuck like I was, then you should try it, until you find a better solution.虽然那个版本已经过时了,可能不建议任何人使用它,但如果你仍然像我一样被卡住,那么你应该尝试一下,直到找到更好的解决方案。

Just write these commands:只需编写以下命令:

npx create-react-app my-app npx 创建反应应用程序我的应用程序

cd my-app cd 我的应用程序

npm i --save-dev react-scripts@2.1.8 npm i --save-dev react-scripts@2.1.8

npm start npm启动

That should work and help you get your app on board.这应该可以帮助您获得应用程序。 I hope this helps someone.我希望这可以帮助别人。

It is because you have added insufficient paths in your Environmental variables.这是因为您在环境变量中添加的路径不足。

First you can do is close the vs code,首先你可以做的是关闭vs代码,

Go to the properties of My Pc, Go 到我的电脑的属性,

Click on Advanced Settings,点击高级设置,

click on Environmental Variables,点击环境变量,

from there you can add path clicking the path variables in the table.从那里您可以添加路径,单击表中的路径变量。 Add a new line to the path and copy paste the path of your system 32,在路径中添加新行并复制粘贴系统的路径 32,

C:\Windows\System32 C:\Windows\System32

hope this solution works in your case希望此解决方案适用于您的情况

(I've been trying to fix this problem for so long this is the only solution i found that worked) (我一直试图解决这个问题很长时间,这是我发现的唯一有效的解决方案)

i was also facing this same issue.我也面临同样的问题。 after spending some time i just simply install the node.js most user version.花了一些时间后,我只是简单地安装了 node.js 大多数用户版本。 and now issue is fixed.现在问题已解决。 before it was installed latest version of node js.在安装最新版本的节点 js 之前。

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

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