Build error using webpack with env2
Closed this issue ยท 6 comments
I npm installed env2 into a project to configure and access my environment variables. When I go to run the build with webpack, it keeps throwing an error:
WARNING in ./~/env2/lib/env.js
Critical dependencies:
31:69-76 require function is used in a way in which dependencies cannot be statically extracted
@ ./~/env2/lib/env.js 31:69-76
ERROR in ./~/env2/package.json
Module parse failed: /node_modules/env2/package.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
| "name": "env2",
| "version": "2.0.6",
| "description": "Environment Variable Loader",
@ ./~/env2/lib/env.js 82:18-44
I included a plugin in the webpack.development.config.js
file but the problem still persists. Plugin:
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"development"'
})
I was wondering if anyone has had a similar issue?
Hi @jackcarlisle I don't understand why webpack
needs to "bundle" the environment variables...
can you please link to the code where you are seeing this issue?
@nelsonic here's the code https://github.com/dwyl/learn-aws-iot/blob/fd72ee7bd20feb2c6169db5d58526ce582abac5b/src/js/utils/request.js
@rjmk was saying that it was because webpack does static module resolution and that the fix required in env2 would be to replace the require call with reading the file (sync) and then JSON.parse-ing it. I'm currently looking in to this
@jackcarlisle oh. we can fix that quite easily. thanks @rjmk ๐
see:
Line 31 in 9f07c9d
@jackcarlisle are you still having this issue? if not, please close the issue. thanks. ๐
Hi there, I'm facing this issue. Is there a way around it?