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

This is driving me crazy: Error: Failed to find .env file at path: ./devOps/env/env.js #369

Open
cyango opened this issue Oct 18, 2023 · 5 comments

Comments

@cyango
Copy link

cyango commented Oct 18, 2023

I have created a env.js file that i want to use with dynamic vars (that's why i'm using js)
I'm using the same logic in many other apps and it works fine with env-cmd
But on a specific project that has the same files and same folder structure, basically everything is the same. It gives this error:

Error: Failed to find .env file at path: ./devOps/env/env.js

Everything i do i doens't work, i removed node_modules, package-lock, gitignore, dockerignore, every .ignore

running this command: env-cmd -f ./devOps/env/env.js react-scripts start

what am I doing wrong?

@gganster
Copy link

same here

@cyango
Copy link
Author

cyango commented Oct 26, 2023

Also my react app is completely ignoring env-cmd with a simple env-cmd -f .env.android react scripts build.
@toddbluhm can you help?

@LizDodion
Copy link

same. works for pnpm env:cmd not with npm

@cyantree
Copy link

cyantree commented Feb 9, 2024

Are you using this in an ESM setup? It seems the package currently doesn't support ESM and in this case fails with this error and hides the original one:

Error [ERR_REQUIRE_ESM]: require() of ES Module [...]\.env.js from [...]\node_modules\.pnpm\env-cmd@10.1.0\node_modules\env-cmd\dist\parse-env-file.js not supported.
.env.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules. 
Instead either rename .env.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in [...]\package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead). 

    at Object.getEnvFileVars ([...]\node_modules\.pnpm\env-cmd@10.1.0\node_modules\env-cmd\dist\parse-env-file.js:21:33)

@caph1993
Copy link

caph1993 commented Apr 19, 2024

Same here.
Remarks:

  1. If I rename my env file from env.js to env.cjs, then I get rid of the message but the file is ignored. (this is even worst)
  2. A solution in my case was ro remove "type": "module" from the package.json of the folder and its parent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants