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

dotenv-webpack not working. env file not loaded. variables are undefined #496

Open
wibed opened this issue Apr 24, 2023 · 4 comments
Open

Comments

@wibed
Copy link

wibed commented Apr 24, 2023

using esm module based project

{
  "start": "npm run clean && cross-env NODE_ENV=development NODE_OPTIONS=\"--loader=ts-node/esm --trace-warnings\" webpack serve --mode=development --config webpack.config.ts"
}

dotenv-webpack does not prevent the app from starting, any env variable ends up beeing undefined.
other plugins work as expected, thats why i dont assume my webpack.config.ts to be wrong

i load it as usual
as new Dotenv() entry in the plugin section:

...
import Dotenv from 'dotenv-webpack'
...
  plugins: [
    miniCSSPlugin,
    copyPlugin,
    htmlPlugin,
    forkCheckerPlugin,
    new Dotenv()
  ],
...
@wibed wibed changed the title get MISSING_ENV_VAR on esm modules dotenv-webpack not working. env file not loaded. any var is undefined Aug 21, 2023
@wibed wibed changed the title dotenv-webpack not working. env file not loaded. any var is undefined dotenv-webpack not working. env file not loaded. variables are undefined Aug 21, 2023
@TranquilMarmot
Copy link

Running into this as well; it seems like it's not loading the .env file no matter what I try

@cosi-conda
Copy link

cosi-conda commented Oct 13, 2023

Have you tried this?

package.json:
"build:local": "webpack --mode development --env NODE_ENV=local",

webpack config:

module.exports = async (env, options) => {
...

      new DotenvWebpackPlugin({
        systemvars: true,
        path: `./env/.env.${env.NODE_ENV}` // This means the env files are in a folder called `env` at the root
      }),

@wibed
Copy link
Author

wibed commented Oct 14, 2023

for me this is not working right.

i had some success installing process, but it remained empty even after setting up
ProvidePlugin, further specifying process: process/browser

accessible but remained empty. the path was set up as explained above.

@mrsteele
Copy link
Owner

The problem might be legitimate. I don’t have a lot of experience with module npm support. Anyone else here able to check out my code to see what’s going on?

also, if anyone has a simplified boilerplate here I could download that and give it a try.

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

No branches or pull requests

4 participants