-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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_require__(...) is not a function with babel-loader #1223
Comments
i have same issue, but with |
Thanks for reporting this bug it looks like it was already reported a while back here without a solution: And you are right it is a duplicate of #637 unfortunately we didn't really understand what is causing the bug. Thanks to your reproduction repository I was able to do some quick tests and realized that it breaks for html-webpack-plugin 3.2 and 4.x because of a webpack behaviour which I don't understand. To debug those the bug I used node inspector like the following: node --inspect-brk node_modules/.bin/webpack The bug starts from the Inside that sandbox it uses the code generated by the /***/ "./node_modules/html-webpack-plugin/lib/loader.js!./index.html":
/*!*********************************************************************!*\
!*** ./node_modules/html-webpack-plugin/lib/loader.js!./index.html ***!
\*********************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
var _ = __webpack_require__( /*! !./node_modules/lodash/lodash.js */ "./node_modules/lodash/lodash.js");
module.exports = function(templateParams) {
with(templateParams) {
return (function(data) {
var __t, __p = '';
__p += '<!DOCTYPE html>\n<html>\n <head>\n <title>Test</title>\n <meta charset="utf-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />\n </head>\n <body class="loading">\n <div id="app"></div>\n </body>\n</html>\n';
return __p
})();
}
}
/***/
}), Now webpack kicks in for Webpack loads the Webpack tries to wrap the harmony-module (
module.exports = function(originalModule) {
if (!originalModule.webpackPolyfill) {
var module = Object.create(originalModule);
// module.parent = undefined by default
if (!module.children) module.children = [];
Object.defineProperty(module, "loaded", {
enumerable: true,
get: function() {
return module.l;
}
});
Object.defineProperty(module, "id", {
enumerable: true,
get: function() {
return module.i;
}
});
Object.defineProperty(module, "exports", {
enumerable: true
});
module.webpackPolyfill = 1;
}
return module;
}; Now it gets strange: webpack tries to wrap Unfortunately I don't understand why this is happening so I won't be able to provide a solution here - maybe @sokra can lead us into the correct direction. What we could do as a workaround is to try to use the nodejs require instead of The workaround (#1239) would be to replace this line html-webpack-plugin/lib/loader.js Line 28 in 895db29
with: return 'var _ = __non_webpack_require__(' + require.resolve('lodash') + ');' + |
Interesting findings! Overall I found it odd that html-webpack-plugin uses webpack to resolve lodash (and any other internal dependencies), so ensuring that it gets loaded via node |
The problem is documented here: https://babeljs.io/docs/en/options#sourcetype |
TL'DR
|
Expected behaviour
Using babel-loader and html-webpack-plugin shouldn't require any special configuration.
Current behaviour
Webpack throws the following error with a minimal repro using only webpack, babel-loader and html-webpack-plugin:
Environment
Node.js v12.1.0
darwin 18.6.0
npm 6.9.0
webpack-issue@1.0.0 .../webpack-issue
└── webpack@4.32.2
webpack-issue@1.0.0 .../webpack-issue
└── html-webpack-plugin@3.2.
Config
Relevant Links
Repository with minimal repro repository
Possibly related:
Workaround
The text was updated successfully, but these errors were encountered: