env-cmd 无法在默认路径找到 .rc 文件。

huangapple go评论129阅读模式
英文:

env-cmd Failed to find .rc file at default paths

问题

我正在使用工具env-cmd来管理我的环境变量,但遇到了错误:

> 错误:无法在默认路径找到.rc文件:[./.env-cmdrc,./.env-cmdrc.js,./.env-cmdrc.json]

我已经验证文件(在我的情况下是./.env-cmdrc)确实存在于工作目录中,并具有足够的权限644(任何人都可以读取)。该文件还包含了预期的值。

不是由于使用错误的标志/语法来查找环境文件而导致的。

运行的命令格式为env-cmd -e ENVIRONMENT_NAME

为什么会出现这个错误?

英文:

I am using the tool env-cmd to manage my environment variables, and am encountering the error:

> Error: Failed to find .rc file at default paths: [./.env-cmdrc,./.env-cmdrc.js,./.env-cmdrc.json]

I have verified that the file (in my case ./.env-cmdrc) does exist in the working directory and has sufficient permissions 644 (anyone can read). The file also contains the expected values.

This is not a result of using the wrong flag/syntax to find the env file as other questions are.

The command being ran is formatted as env-cmd -e ENVIRONMENT_NAME

Why is this error thrown?

答案1

得分: 3

抱歉,这个库在某些情况下会出现误导性的错误,实际上文件是存在的。

环境文件中的JSON格式错误

经常报告这个错误的原因是文件中的JSON格式无效。(GitHub问题). 常见的问题是尾随逗号,但也可能是其他原因。

环境文件中缺少环境

当使用一个包含多个环境的 env-cmdrc 文件(参见 高级用法),如果命令中指定的环境在文件中不存在,就会引发此错误。

在我的情况下,我使用一个变量确定目标环境,但该变量的值是 undefined,导致执行 env-cmd -e undefined。JSON 文件中没有名为 undefined 的键,因此会引发错误。


这是我迄今为止发现的两种不正当引起该错误的情况。这个库已经有3年没有更新了,因此修复的可能性似乎不大。

英文:

Unfortunately, this library throws this misleading error in a few different cases when the file is actually present.

Malformed JSON in the env file

A commonly reported source of this error is invalid JSON in the file. (GitHub issue). Trailing commas are common, but it could be from a variety of causes.

Missing environment in env file

When using an env-cmdrc file with multiple environments (see Advanced Usage), this error is thrown when the environment specified in the command is not present in the file.

In my case, I was using a variable to determine the target environment which was undefined, resulting in env-cmd -e undefined. The JSON did not have a key called undefined which causes the error to be thrown.


These are the only two scenarios I have found that illegitimately cause this error so far. The library has not been updated in 3 years, so it seems unlikely that it will be fixed.

huangapple
  • 本文由 发表于 2023年4月6日 22:58:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75950956.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定