New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webpack 5 output with "commonjs2" and "externals" can't be loaded by Webpack 4 #17730
Comments
I wonder if this issue is part of a greater one. I am having a bunch of miscellaneous issues in a Webpack 4 host app, once I updated my package to Webpack 5. I had just posted https://stackoverflow.com/questions/77289969/why-does-webpack-5-build-fail-upstream-with-devtool-false on SO. Then I realized i was bumping into more issues, including like yours. I get I had updated my code from using |
This issue had no activity for at least three months. It's subject to automatic issue closing if there is no activity in the next 15 days. |
bump |
I guess we had a PR for this.. I will take a look |
Bug report
What is the current behavior?
When using Webpack5 with
library.type
ofcommonjs2
andexternals
set, the resulting output cannot be consumed by Webpack 4.The app doesn't load, and the following error appears in dev tools:
Repro steps
*** Additional details ***
Looking at
lib/dist/index.js
, we see the following line at the start:This overwrites the
__webpack_require__
global that Webpack 4 expects, which leads to the error detailed above.Setting minimzation in
lib/webpack.config.js
as follows will avoid this issue:However, it's not actually necessary to minimize - simply renaming the
__webpack_require__
var inlib/dist/index.js
will likewise fix the issue, since it will no longer override the Webpack 4 global.What is the expected behavior?
The app should load with no errors in the console and output "Webpack 4 App Loaded!" in the console.
Other relevant information:
webpack version: 5.88.2 for the lib, 4.47.0 for the app
Node.js version: 14
Operating System: macOS
Additional tools:
The text was updated successfully, but these errors were encountered: