env-cmd icon indicating copy to clipboard operation
env-cmd copied to clipboard

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

Open dcp3450 opened this issue 2 years ago • 4 comments

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.

dcp3450 avatar Apr 13 '23 21:04 dcp3450

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 avatar Apr 17 '23 20:04 anichols-ht

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 avatar Apr 17 '23 20:04 anichols-ht

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.

anichols-ht avatar Apr 17 '23 20:04 anichols-ht