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

'TypeError: fs.readFileSync is not a function' when used with webpack #129

Closed
patoncrispy opened this issue Mar 14, 2016 · 4 comments
Closed

Comments

@patoncrispy
Copy link

I'm not sure why, but when I try to use dotenv in my app I get the above error message in my console.
I'm importing dotenv the es6 way:

import dotenv from 'dotenv';
dotenv.config();

But for some reason, I'm getting that error. The following tickets on other packages suggest it's something to to with webpack, but I don't understand what it could be:
browserify/brfs#36
pixijs/pixijs#2078

The fixes on those sites do not solve the issue I am having, either. :(

@jcblw
Copy link
Collaborator

jcblw commented Mar 14, 2016

I recommend against using this client-side like this, essentially what would need to happen for this to work the client is that the entire file would need to be included into the client bundle so we could parse the data. Issue is that a lot of the time .env is where you should put sensitive data that you do not want to keep inside your revision history, and doing this would make all the info available to anyone who can look at the source of your site.

A method I have used is injecting the values into the views of the website, if you are running a node server. Or another option is if you have a static site, write the needed variables to a file that could be bundled with webpack or browserify.

Sorry for the not so straight forward answer.

@patoncrispy
Copy link
Author

That actually makes perfect sense. I feel silly for not thinking of that myself! Thanks for the tip! 

On Mon, Mar 14, 2016 at 11:15 AM -0700, "Jacob Lowe" notifications@github.com wrote:

I recommend against using this client-side like this, essentially what would need to happen for this to work the client is that the entire file would need to be included into the client bundle so we could parse the data. Issue is that a lot of the time .env is where you should put sensitive data that you do not want to keep inside your revision history, and doing this would make all the info available to anyone who can look at the source of your site.

A method I have used is injecting the values into the views of the website, if you are running a node server. Or another option is if you have a static site, write the needed variables to a file that could be bundled with webpack or browserify.

Sorry for the not so straight forward answer.


Reply to this email directly or view it on GitHub.

@jcblw
Copy link
Collaborator

jcblw commented Mar 14, 2016

🍻 closing down this issue

@jcblw jcblw closed this as completed Mar 14, 2016
@heymartinadams
Copy link

heymartinadams commented Jan 15, 2017

Good catch, @patoncrispy. Would never have found it on my own. Thanks.

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

3 participants