Hi, team,
Found an interesting bug:
IssueUsing 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 CauseI 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.
mooncakelmn, HaNdTriX, piranna, kilgarenone, Jimmerz28 and 7 more
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4