- Notifications
You must be signed in to change notification settings - Fork76
Open
Description
Hi, team,
Found an interesting bug:
Issue
Using dotent-webpack@1.5.3 and webpack@3.3.0,
// .envDB_HOST=127.0.0.1DB_PASS=foobarS3_API=mysecretkeyUse the vars in JS:
const{DB_HOST,DB_PASS}=process.env;
Would cause runtime error:
Uncaught (in promise) ReferenceError: process is not definedExpected
It should replace both vars at compile time.
Possible Root Cause
I believe this issue is caused bywebpack/webpack#5215
So I changed the JS to:
const{DB_HOST}=process.env;const{DB_PASS}=process.env;
It works well as expected.
I debugged the plugin and found that the underlyingformatData (https://github.com/mrsteele/dotenv-webpack/blob/master/src/index.js#L63) transferred towebpack.DefinePlugin is:
{'process.env.DB_HOST':'"127.0.0.1"','process.env.DB_PASS':'"foobar"','process.env.S3_API':'"mysecretkey"'}
However the format that recommended inwebpack/webpack#5215 (comment) is:
newDefinePlugin({"process.env":{a:JSON.stringify("a"),b:JSON.stringify("b")}})
So I guess a minor fix indotenv-webpack would solve the issue.
However, I think it ought to be awebpack.DefinePlugin regression bug, since it the currentformatData used to work well with webpack 2.
What do you think? Thanks.
Metadata
Metadata
Assignees
Labels
No labels