You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to upgrade my stack from webpack 4 to webpack 5. And got the following error from dotenv-webpack:
[webpack-cli] TypeError: Cannot read property 'startsWith' of undefined
at Dotenv.shouldStub (F:\_projects_\...\node_modules\dotenv-webpack\dist\index.js:210:20)
at Dotenv.formatData (F:\_projects_\...\node_modules\dotenv-webpack\dist\index.js:192:16)
at Dotenv.apply (F:\_projects_\...\node_modules\dotenv-webpack\dist\index.js:66:23)
at WrappedPlugin.apply (F:\_projects_\...\node_modules\speed-measure-webpack-plugin\WrappedPlugin\index.js:292:29)
at createCompiler (F:\_projects_\...\node_modules\webpack\lib\webpack.js:71:12)
at create (F:\_projects_\...\node_modules\webpack\lib\webpack.js:118:16)
at webpack (F:\_projects_\...\node_modules\webpack\lib\webpack.js:126:47)
at WebpackCLI.f [as webpack] (F:\_projects_\...\node_modules\webpack\lib\index.js:41:15)
at WebpackCLI.createCompiler (F:\_projects_\...\node_modules\webpack-cli\lib\webpack-cli.js:1678:29)
at async WebpackCLI.buildCommand (F:\_projects_\...\node_modules\webpack-cli\lib\webpack-cli.js:1785:20)
at async Command.<anonymous> (F:\_projects_\...\node_modules\webpack-cli\lib\webpack-cli.js:564:25)
at async Promise.all (index 1)
at async Command.<anonymous> (F:\_projects_\...\node_modules\webpack-cli\lib\webpack-cli.js:1120:13)
error Command failed with exit code 2.
Further debugging, I've found that compiler.webpack.version is undefined.
I've used patch-package to patch dotenv-webpack@7.0.1 to make it work. Here is the diff that solved my problem:
diff --git a/node_modules/dotenv-webpack/dist/index.js b/node_modules/dotenv-webpack/dist/index.js
index cf85f6c..f1d8b8b 100644
--- a/node_modules/dotenv-webpack/dist/index.js+++ b/node_modules/dotenv-webpack/dist/index.js@@ -62,7 +62,7 @@ var Dotenv = /*#__PURE__*/function () {
var variables = this.gatherVariables();
var target = (_compiler$options$tar = compiler.options.target) !== null && _compiler$options$tar !== void 0 ? _compiler$options$tar : 'web';
- var version = compiler.webpack.version;+ var version = compiler.webpack.version ?? '5';
var data = this.formatData({
variables: variables,
target: target,
Hi! 👋
Firstly, thanks for your work on this project! 🙂
I was trying to upgrade my stack from webpack 4 to webpack 5. And got the following error from
dotenv-webpack
:Further debugging, I've found that
compiler.webpack.version
is undefined.I've used patch-package to patch
dotenv-webpack@7.0.1
to make it work. Here is the diff that solved my problem:This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: