javascript - 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.
解决方案
您可以使用您自己的带有标志的自定义.env
文件设置环境变量。使用此命令设置自定义文件中定义的变量。-f
env-cmd
env
'./config/myvar.env'
env-cmd -f ./config/myvar.env
有关更多信息,请使用此链接
推荐阅读
- python - 需要帮助理解 Jurafsky 和 Martin 对简单聊天机器人的解释
- java - Gremlin 获得共享相同顶点的边
- azure - 使用 OAuth2 提供程序的 Azure AD B2C 社交登录
- python - 在进行行总和后获取 Pandas 数据框的列值时出错
- php - 强制加载不需要的 php 文件
- node.js - MEAN Stack 无法使用 PUT 方法更新 MongoDB 记录
- javascript - 如何跳过对象数组中的零值?
- amazon-web-services - 在 AWS Lambda 中访问的 s3 数据的 Cloudfront CDN
- laravel - 我应该将 CloudFront 一起用作 s3 中敏感文件的 TemporaryUrl
- javascript - 可变乘数