Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to find .env file if options are not in correct order #357

Open
kmathmann opened this issue Feb 6, 2023 · 1 comment
Open

Failed to find .env file if options are not in correct order #357

kmathmann opened this issue Feb 6, 2023 · 1 comment
Assignees
Labels

Comments

@kmathmann
Copy link

The Problem

I expect that the order of options isn't affecting the execution. These two options should both work the same way.

  1. ./node_modules/.bin/env-cmd -r .env-cmdrc -e development --use-shell 'echo "$TEST"'
  2. ./node_modules/.bin/env-cmd -r .env-cmdrc --use-shell 'echo "$TEST"' -e development

The position of -e is different

But the second results in the following error while the first one works:

Error: Failed to find .env file at default paths: [./.env,./.env.js,./.env.json]
    at getEnvFile (/<...>/node_modules/env-cmd/dist/get-env-vars.js:58:11)
    at async Object.EnvCmd (/<...>/node_modules/env-cmd/dist/env-cmd.js:39:15)
    at async Object.CLI (/<...>/node_modules/env-cmd/dist/env-cmd.js:19:16)

Why we need -e to be the last option

We are using multiple npm scripts for different environments. For example build:staging and build:prod. To reduce the boilerplate code of repeating everything except the -e option we want to create a general build task without the -e option that can be called in other npm scripts like this: npm run build -e development.

@toddbluhm
Copy link
Owner

Yeah, this is a bug and actually should be fixed in the latest master. You now have to use -- to separate the command from the env-cmd options. This is a result of updating commander which is used for parsing command line args.

@toddbluhm toddbluhm added the bug label Dec 9, 2024
@toddbluhm toddbluhm self-assigned this Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants