问题描述
我使用 create-react-app 并尝试使用 HOST=custom.local
文件设置 .env
变量。
但它总是被消息忽略:
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
解决方法
看起来我的问题不是由重新分配变量引起的,而是因为我的自定义主机名 custom.localhost
没有映射到任何 IP,即使没有这样的消息。
除了将域添加到 0.0.0.0 custom.localhost
文件之外,还通过在我的 /etc/hosts
中添加 .env
解决了该问题。