env-cmd: Failed to find .rc file at default paths: [./.env-cmdrc,./.env-cmdrc.js,./.env-cmdrc.json]
This has been reported already in #118 but the OP closed it. The reason for this error message in both my case in issue 118’s OP was that the .env-cmd was not valid JSON and could not be parsed correctly which would have been much more helpful error message than this confusing information about env-cmd not being able to find the .rc file. The issue lies here in get-env-var.js inside the catch that is muting all exceptions except EnvironmentError, I added a comment and console.log there to debug locally:
for (const path of RC_FILE_DEFAULT_LOCATIONS) {
try {
const env = await parse_rc_file_1.getRCFileVars({ environments, filePath: path });
if (verbose === true) {
console.info(`Found environments: [${environments.join(',')}] for default .rc file at path: ${path}`);
}
return env;
}
catch (e) {
// not sure why you want mute exceptions other than "EnvironmentError", add the console.log in the line below to see the true error being muted.
console.log(`ERROR: ${e}`);
if (e.name === 'EnvironmentError') {
const errorText = `Failed to find environments: [${environments.join(',')}] for .rc file at path: ${path}`;
if (verbose === true) {
console.info(errorText);
}
throw new Error(errorText);
}
}
}
Maybe you could just rethrow the error below the “if” statement to make sure errors are not muted.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 21
- Comments: 16 (3 by maintainers)
thanks, in my case I had a trailing comma
The same error happens when trying to use
type: "module"(ES Module) inpackage.jsonits most likely a syntax error for me my env-cmdrc had a comma in the last key value pair in the development section.
This confused me because I thought env-cmd couldn’t find my configuration file, since that was the only error I saw. It turned out it was an error in my configuration code causing the issue. I’d definitely suggest outputting any errors to the console.
Thanks for bringing this up. I need to do some refactoring around how error handling/propagation works anyways. I will fix this while I am at it 😄