首页 > 解决方案 > env-cmd 错误未能在 gatsby 中找到 ./.env 文件?

问题描述

我在根文件夹中有一个文件名 .env.development 。
启动服务器时,我已将 env-cmd 安装为开发依赖项

  > npm run develop

它给了我一个错误

> gatsby-starter-hello-world@0.1.0 develop I:\learngatsby
> env-cmd .env-development gatsby develop

(node:1368) UnhandledPromiseRejectionWarning: Error: Unable to locate env file at default location (./.env)
at I:\learngatsby\node_modules\env-cmd\dist\get-env-vars.js:44:19
at Generator.throw (<anonymous>)
at rejected (I:\learngatsby\node_modules\env-cmd\dist\get-env-vars.js:5:65)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:757:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
(node:1368) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:1368) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

标签: javascriptnode.js

解决方案


您可以使用您自己的带有标志的自定义.env文件设置环境变量。使用此命令设置自定义文件中定义的变量。-fenv-cmdenv'./config/myvar.env'

env-cmd -f ./config/myvar.env

有关更多信息,请使用此链接


推荐阅读