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

Does not work with webpack-dev-server #78

Closed
screendriver opened this issue Aug 17, 2017 · 14 comments
Closed

Does not work with webpack-dev-server #78

screendriver opened this issue Aug 17, 2017 · 14 comments

Comments

@screendriver
Copy link

Hi,

it seems that dotenv-webpack does not work with webpack-dev-server. In my normal builds without webpack-dev-server I can see that the env variables are replaced as expected. But when I use webpack-dev-server all my env variables are undefined.

webpack: 3.5.5
webpack-dev-server: 2.7.1
dotenv-webpack: 1.5.4

@jbailey
Copy link

jbailey commented Sep 7, 2017

Any good ways around this? Seeing the same thing.

@mrsteele
Copy link
Owner

mrsteele commented Sep 7, 2017

Hey @screendriver (and @jbailey), sorry somehow this issue slipped through the cracks.

Just to jump-start me to get this resolved quickly, do you have a repo in progress/PR that I can look at to know more about your configuration?

@mrsteele
Copy link
Owner

mrsteele commented Sep 7, 2017

I use my dotenv-webpack-example library to test out some of these issues and I just made a commit to it that has a working example with webpack-dev-server.

Feel free to have a look.

https://github.com/mrsteele/dotenv-webpack-example

Of course, this is a minimally configured approach so it may or may not help you out. Since it can work I imagine you may have something else going on and conflicting with your variables. Since it has occurred more than once it may be a common problem but I am more than happy to investigate.

@jbailey
Copy link

jbailey commented Sep 7, 2017

Hmm, my webpack config looks the same, i just dont get the env variables from the file. I've tried in two different projects. I'm using webpack 2.2.1 for what it's worth.

EDIT: I upgraded to webpack 3.5.6 without luck.

@mrsteele
Copy link
Owner

mrsteele commented Sep 7, 2017

I went ahead and upgraded everything and it still works. Do you have any other plugins that may be conflicting (historically that is what it ends up being).

$ npm ls --depth=0
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

@screendriver
Copy link
Author

I don't know how or what changed but in the meantime it's working on my machine 😳 🤔

@mrsteele
Copy link
Owner

Adding the help wanted label and maybe others can contribute if they have any problems as well.

@denizdogan
Copy link

For what it's worth, I use webpack-dev-server with dotenv-webpack without any issues.

@mrsteele
Copy link
Owner

Haha from where I’m sitting @denizdogan it’s worth a lot!

@nickbouldien
Copy link

I just installed dotenv-webpack, and initially had the same issue as screendriver (OP), with it showing all the .env vars as undefined, but after killing the server a few times and rebuilding/restarting, it worked

I know that doesn't help on this, just thought it was interesting

@cbovis
Copy link

cbovis commented Apr 14, 2018

Can confirm I'm also not seeing any issues using dotenv-webpack with webpack-dev-server. Worked first time.

webpack: 3.11.0
webpack-dev-server: 2.11.1
dotenv-webpack: 1.5.5

@mrsteele
Copy link
Owner

Thanks @cbovis I'm going to assume this is resolved at this point but @screendriver if you think this is still a problem feel free to reopen.

@screendriver
Copy link
Author

Hi @mrsteele,

on my machine it works again. I don't know why but the main thing is it works 😁 So it's ok for me to close the issue 😉

@evenfrost
Copy link

In case anyone stumbles upon a similar issue, make sure you're not destructuring process.env as it doesn't currently work. Instead, use full notation when referring to environment vars, e.g. process.env.YOUR_ENV_VAR.

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

7 participants