【问题标题】:Server doesn't work with HOST variable in .env (Create React App)服务器不适用于 .env 中的 HOST 变量(创建 React 应用程序)
【发布时间】:2021-09-16 05:50:36
【问题描述】:

我使用 create-react-app 并尝试使用 .env 文件设置 HOST=custom.local 变量。 但它总是被消息忽略:

Attempting to bind to HOST environment variable: custom.localhost
If this was unintentional, check that you haven't mistakenly set it in your shell.

另外,我看到了这个:

echo $HOST
M1-Air // <- my laptop name

那么,我如何理解这个变量已经设置并且 CRA 中的 dotenv 不会覆盖它而只是忽略,但是关于我需要做什么来为 CRA 设置我的自定义 HOST 变量有什么建议吗?

我在 GitHub 上发现了一个类似的问题,但没有关于如何解决它的任何建议: https://github.com/facebook/create-react-app/issues/4307

【问题讨论】:

    标签: environment-variables localhost create-react-app dotenv


    【解决方案1】:

    看起来我的问题不是由重新分配变量引起的,而是因为我的自定义主机名 custom.localhost 没有映射到任何 IP,即使没有这样的消息。

    除了将域添加到.env 文件之外,还通过在我的/etc/hosts 中添加0.0.0.0 custom.localhost 解决了这个问题。

    我在这里找到了答案:https://stackoverflow.com/a/52595624/344306

    【讨论】:

      猜你喜欢
      • 2023-02-08
      • 1970-01-01
      • 1970-01-01
      • 2021-10-27
      • 2014-04-19
      • 2020-11-25
      • 2021-01-11
      • 1970-01-01
      • 2020-02-09
      相关资源
      最近更新 更多