npm start on new create-react-app build 返回 ELIFECYCLE 错误

IT技术 reactjs macos npm terminal
2021-04-29 06:19:35

使用 create-react-app 制作了一个新的react应用程序,现在在运行 npm start 时在终端中收到以下错误:

> react-scripts start

Attempting to bind to HOST environment variable: x86_64-apple-darwin13.4.0
If this was unintentional, check that you haven't mistakenly set it in your shell.


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

Error: getaddrinfo ENOTFOUND x86_64-apple-darwin13.4.0
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)
Emitted 'error' event at:
    at GetAddrInfoReqWrap.doListen [as callback] (net.js:1468:12)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! aqi@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the aqi@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!     /Users/chris/.npm/_logs/2018-12-24T10_07_46_970Z-debug.log 

尝试删除 node-module 文件夹和 npm install。

4个回答

键入unset HOST在终端中。它将解决问题。

我一整天都在为这个确切的问题而苦苦挣扎。如果你这样做unset HOST,它会解决它,但暂时的这个bug的简单解决方案如下(这是针对Mac的,对于Window,命令可能会有所不同):

  1. 使用以下命令打开您的 bash:open ~/.bash_profile
  2. 文件打开后,将其(正是它所说的)一直写到文件中: HOST="localhost"
  3. 之后,保存文件并退出(Command + q)
  4. 最后,通过在终端上键入以下内容来重新加载环境: source ~/.bash_profile

如果您正确执行所有步骤,这应该可以解决该错误。

我也为此苦苦挣扎。许多在线解决方案只解决了第一部分。在这里,我将提供我的方法来完全解决问题并使 npm 开始工作

理解问题:

问题有两个部分。首先,您要将环境变量 HOST 设置为“localhost”。您可以通过在终端(任何地方)中输入来完成:

  1. 纳米 ~/.bash_profile
  2. 在 bash 文件中,输入HOST="localhost"一个新行并输入:export HOST. 默认情况下,这会指示您的程序转到此 HOST
  3. 按 Ctrl + X 保存更改,然后按 Y(是),然后按 Enter
  4. 返回终端,运行:source ~/.bash_profile刷新终端

现在,您的计算机已将其 HOST 变量更新为 localhost。您可以通过env | grep HOST在终端中键入:来检查Grep 意味着在变量列表中获取该变量。

希望这能完全解决问题。如果您随后遇到:dyld: lazy symbol binding failed.

这只是意味着 fsevents 有问题。为什么?我不确定,但确定的解决方法是从我的搜索中删除 node_modules/fsevent 文件。永久修复是删除节点module并重新执行 npm 安装。确保 fsevent 是 2.0+ 版本!

希望有帮助。这肯定需要一些时间来调试!

参考:

  1. dyld:懒惰的符号绑定失败:找不到符号:_node_module_register
  2. https://medium.com/@choy/fixing-create-react-app-when-npm-fails-to-start-because-your-host-environment-variable-is-being-4c8a9fa0b461
  3. https://medium.com/@youngstone89/setting-up-environment-variables-in-mac-os-28e5941c771c

我能够通过运行npm install create-react-app而不是npm install -g create-react-app. 希望能帮助到你。