简体   繁体   English

反应脚本 3.4.0 的 npm start 问题

[英]npm start issues with react-scripts 3.4.0

I know this question has already been asked but I can't find a solution.我知道已经有人问过这个问题,但我找不到解决方案。 When I run npm start inside a react project, I always get the same logs (see below).当我在npm start项目中运行npm start ,我总是得到相同的日志(见下文)。 The only solution given is to uninstall node_modules and re-do the installation.给出的唯一解决方案是卸载node_modules并重新安装。 I also tried to clear the cache.我也尝试清除缓存。 Nothing worked.没有任何效果。

Some people solved this problem upgrading to react-scripts 3.4.0 ( https://github.com/facebook/create-react-app/issues/8490 ) but that didn't work for me.有些人解决了升级到react-scripts 3.4.0 ( https://github.com/facebook/create-react-app/issues/8490 ) 的问题,但这对我不起作用。 The only solution I have now is to downgrade react-scripts to version 2.1.8 by using npm install react-scripts@2.1.8 .我现在唯一的解决方案是使用npm install react-scripts@2.1.8react-scripts降级到2.1.8版。 But it's not a good solution because I have to work on a framework that uses the latest version.但这不是一个好的解决方案,因为我必须在使用最新版本的框架上工作。

here are the logs :这是日志:

i 「wds」: Project is running at http://192.168.43.27/
i 「wds」: webpack output is served from /
i 「wds」: Content not from webpack is served from C:\Users\fthom\Desktop\temp\my-app\public
i 「wds」: 404s will fallback to /index.html
Starting the development server...

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

Error: spawn cmd 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 cmd',
  path: 'cmd',
  spawnargs: [ '/s', '/c', 'start', '""', '/b', '"http://localhost:3000/"' ]
}
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\fthom\AppData\Roaming\npm-cache\_logs\2020-02-21T10_59_13_574Z-debug.log

I finally found a solution.我终于找到了解决方案。 Add the default variables in the machines PATH:在机器 PATH 中添加默认变量:

C:\\Windows\\system32 C:\\Windows\\system32
C:\\Windows C:\\Windows
C:\\Windows\\System32\\Wbem C:\\Windows\\System32\\Wbem

Screenshot of variables location变量位置的屏幕截图

Changing the path worked for me.改变路径对我有用。 Just to add, on the above solution for those who didn't know how to change the path (same as me) and some more details.只是补充一下,对于那些不知道如何更改路径(与我相同)和更多细节的人的上述解决方案。

Here is my way on how to change environment variables on Windows 10:这是我如何在 Windows 10 上更改环境变量的方法:

  • Open the Start Search, type in “env”, and choose “Edit the system environment variables”打开开始搜索,输入“env”,然后选择“编辑系统环境变量”
  • Click the Environment Variables… button.单击环境变量...按钮。
  • Go on system variables and under variables find PATH, mark it and click EDIT .继续系统变量并在变量下找到 PATH,标记它并单击EDIT
  • On the end of the list add paths - you can simply click on new or on the empty field on the end of list: C:\\Windows\\system32 C:\\Windows C:\\Windows\\System32\\Wbem在列表末尾添加路径 - 您只需单击列表末尾的新字段或空白字段: C:\\Windows\\system32 C:\\Windows C:\\Windows\\System32\\Wbem
  • Remember to have the npm paths as well: C:\\Program Files\\nodejs C:\\Users{yourName}\\AppData\\Roaming\\npm记住还有 npm 路径: C:\\Program Files\\nodejs C:\\Users{yourName}\\AppData\\Roaming\\npm
  • Set the environment variables as needed.根据需要设置环境变量。
  • The New button adds an additional variable. New 按钮添加了一个额外的变量。 ... ...
  • Dismiss all of the dialogs by choosing OK .选择OK关闭所有对话框。 Your changes are saved!您的更改已保存!
  • Restart the computer.重新启动计算机。

Now it should work!现在它应该可以工作了!

It took me two days to resolve this issue.我花了两天时间才解决这个问题。

Its because of the incompatibility issue of react-scripts so try installing different versions like:这是因为 react-scripts 的不兼容问题,所以尝试安装不同的版本,例如:

This worked for me:这对我有用:

npm install --save react-scripts@2.1.8

This one did work for many as they claim:正如他们声称的那样,这个确实对许多人有用:

npm install --save react-scripts@3.3.0

It should work as it did to me after an arduous struggle.经过艰苦的斗争,它应该像对我一样起作用。

Sometimes on windows, I get the same error message randomly if the npm cache is somehow messed up.有时在 Windows 上,如果 npm 缓存不知何故搞砸了,我会随机收到相同的错误消息。

Try to run尝试运行

npm cache clean --force

Delete the node_modules folder and the package.lock.json file and run npm install afterward.删除node_modules文件夹和package.lock.json文件,然后运行npm install

  1. Open the Start Search, type in “env”, and choose “Edit the system environment variables打开开始搜索,输入“env”,然后选择“编辑系统环境变量”

  2. Click the Environment Variables Button.单击环境变量按钮。

  3. Go on system variables and under variables find PATH, mark it and click EDIT.继续系统变量并在变量下找到 PATH,标记它并单击 EDIT。

  4. On the end of the list add paths - you can simply click on new or on the empty field在列表的末尾添加路径 - 您只需单击新的或空白的字段

  5. Go to your react app folder then go to node_modules and then go to bin folder and then copy url转到您的 react app 文件夹,然后转到node_modules ,然后转到bin文件夹,然后复制 url

  6. Paste your url in new path将您的网址粘贴到新路径中

暂无
暂无

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

相关问题 npm run build的react-scripts问题 - react-scripts issues with npm run build 反应脚本:找不到命令(npm start) - react-scripts: command not found (npm start) npm 启动失败:错误:启动:`react-scripts start` - npm start failing: Error: start: `react-scripts start` npm start throws sh: react-scripts: command not found - npm start throws sh: react-scripts: command not found npm start reactjs,无法启动,react-scripts:找不到命令 - npm start reactjs, won't start, react-scripts: command not found create-react-app + npm start - 'react-scripts' 不被识别为内部或外部命令 - create-react-app + npm start - 'react-scripts' is not recognized as an internal or external command Node/WebpackDevServer/react-scripts,删除“To create a production build, use npm run build”消息 - Node/WebpackDevServer/react-scripts, remove “To create a production build, use npm run build” message on start 命令“npm start”中的问题在第四个 tic-tac-toe@0.1.0 启动脚本中失败。 npm ERR:反应脚本:未找到 - Problem in the command "npm start" Failed at the fourth-tic-tac-toe@0.1.0 start script. npm ERR! react-scripts: not found 我如何修复错误反应脚本启动。 导入 ml5 后反应 npm start 出现此错误 - how can i fix error react-scripts start. react npm start gets this error after import ml5 npm install 成功,但 npm run start 无法找到 rimraf 和 react-scripts 尽管它们已安装 - npm install succeeds but npm run start fails to find both rimraf and react-scripts despite them being installed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM