I do not have 'fs' installed, but when I use webpack, I get an error that 'fs' cannot be resolved. dotenv is the only new package added since my last webpack compile.
If it is a dependency, shouldn't it be listed in the package.json for the project? If it is not a dependency, can anyone give me a hint toward figuring out what I've done wrong?
I've tracked this to a Webpack issue that requires a weird work-around. Basically, adding target: 'node' to the Webpack config fixed this.
I don't understand the cause or the fix, really, but this is clearly not an issue with this package.
@trip-somers this issue might have some insight to the issue your running into, and maybe some ways to fix it #153
webpack includes DefinePlugin which accomplishes what dotenv would. Facebook's create-react-app uses it to populate a familiar process.env. In most cases, any environment variable you are sharing to a browser is safe to share to git
I'm confused about how I didn't see #153 before I posted this issue. That would have saved me some time...
FWIW, I worked around this by moving the .env specific part of the code into an HTML template where I set a global JS variable for the value I need. Thanks for the comments.
I faced Error: Can't resolve 'fs' when trying npm run build:dll in react-boilerplate. It turned out that I accidentally listed dotenv in dependencies rather than devDependencies and after ctrl+x & ctrl+v the issue was gone.
It can't be on accident when the README tells you to install with --save-dev though, right? I think some clarification is necessary here.
common workaround, use https://github.com/mrsteele/dotenv-webpack
thank you canercandan.. works a charm
canercandan: THAT WAS EXCELLENT INFO!!!
common workaround, use https://github.com/mrsteele/dotenv-webpack
that doesn't seem to work in a React Native environment, but I did find: react-native-dotenv
Most helpful comment
I've tracked this to a Webpack issue that requires a weird work-around. Basically, adding
target: 'node'to the Webpack config fixed this.I don't understand the cause or the fix, really, but this is clearly not an issue with this package.