Hi, team,
Found an interesting bug:
Issue
Using dotent-webpack@1.5.3 and webpack@3.3.0,
// .env
DB_HOST=127.0.0.1
DB_PASS=foobar
S3_API=mysecretkey
Use the vars in JS:
const { DB_HOST, DB_PASS } = process.env;
Would cause runtime error:
Uncaught (in promise) ReferenceError: process is not defined
Expected
It should replace both vars at compile time.
Possible Root Cause
I believe this issue is caused by webpack/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 underlying formatData (https://github.com/mrsteele/dotenv-webpack/blob/master/src/index.js#L63) transferred to webpack.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 in webpack/webpack#5215 (comment) is:
new DefinePlugin({
"process.env": {
a: JSON.stringify("a"),
b: JSON.stringify("b")
}
})
So I guess a minor fix in dotenv-webpack would solve the issue.
However, I think it ought to be a webpack.DefinePlugin regression bug, since it the current formatData used to work well with webpack 2.
What do you think? Thanks.
Hi, team,
Found an interesting bug:
Issue
Using dotent-webpack@1.5.3 and webpack@3.3.0,
Use the vars in JS:
Would cause runtime error:
Expected
It should replace both vars at compile time.
Possible Root Cause
I believe this issue is caused by webpack/webpack#5215
So I changed the JS to:
It works well as expected.
I debugged the plugin and found that the underlying
formatData(https://github.com/mrsteele/dotenv-webpack/blob/master/src/index.js#L63) transferred towebpack.DefinePluginis:However the format that recommended in webpack/webpack#5215 (comment) is:
So I guess a minor fix in
dotenv-webpackwould solve the issue.However, I think it ought to be a
webpack.DefinePluginregression bug, since it the currentformatDataused to work well with webpack 2.What do you think? Thanks.