toddbluhm / env-cmd

Setting environment variables from a file
https://www.npmjs.com/package/env-cmd
MIT License
1.73k stars 65 forks source link

Using -f is not using a local file, throwing error. #359

Open dcp3450 opened 1 year ago

dcp3450 commented 1 year ago

I have env-cmd installed locally on a windows 10 setup. Calling env-cmd -f .env.local returns the error:

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

I even installed the library in to my app and run it from the ./node_modules/.bin/env-cmd and got the same error.

anichols-ht commented 1 year ago

Same, I don't believe the -f flag works at all. Doesn't seem to matter how I do it.

In my case, I'm in a monorepo and running my startup command from a subdirectory (the cwd is a subdirectory that is), and -f ../../.env.js (or any other filename) fails with the same error you're seeing.

anichols-ht commented 1 year ago

This is why (at least in my case):

{
  envFile: {
    filePath: '/a/path/.env.js',
    fallback: undefined
  },
  rc: { environments: [ 'default', 'local' ], filePath: undefined },
  verbose: false
}

The filePath that gets passed to getRCFile is rc.filePath rather than envFile.filePath.

anichols-ht commented 1 year ago

Ah, there's a separate option for this: -r, --rc-file [path]. With all due respect, I think that's a confusing implementation. It should just always use the -f flag. I can't see any reason you would need to pass both.