Setup via `webpack.config.js` file not working with NamedModulesPlugin
WiseBird opened this issue · 10 comments
Reproduction - https://github.com/WiseBird/expose_loader_named_modules_plugin
I use expose-loader
to expose jquery:
{
test: require.resolve('jquery'),
use: [{
loader: 'expose-loader',
options: 'jQuery'
}]
},
It works without NamedModulesPlugin
while producing next output:
/* 88 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {module.exports = global["jQuery"] = __webpack_require__(89);
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))
/***/ }),
/* 89 */
/***/ (function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
* jQuery JavaScript Library v3.2.1
...
when NamedModulesPlugin
is included output is following:
/***/ "./node_modules/jquery/dist/jquery.js":
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {module.exports = global["jQuery"] = __webpack_require__("./node_modules/jquery/dist/jquery.js");
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__("./node_modules/webpack/buildin/global.js")))
/***/ }),
/***/ "./node_modules/jquery/dist/jquery.js":
/***/ (function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
* jQuery JavaScript Library v3.2.1
So both modules: the one exposing jquery and the one containing jquery have the same name.
Moreover when exposing via require('expose-loader?jQuery!jquery');
the module exposing jquery have different name:
/***/ "./node_modules/expose-loader/index.js?jQuery!./node_modules/jquery/dist/jquery.js":
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {module.exports = global["jQuery"] = __webpack_require__("./node_modules/jquery/dist/jquery.js");
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__("./node_modules/webpack/buildin/global.js")))
/***/ }),
NamedModulesPlugin
uses libIdent
from NormalModule
that in its order uses userRequest
that differs when library exposed via config file or via require statement.
That's a bug in libIdent
webpack/webpack.
There is any progress to fix this bug? I'm trying to migrate a project to webpack and I spent some hours trying to figure out what I was doing wrong and in the end it was this incompatibility between NamedModulesPlugin and expose-loader.
Some other issues related this bug:
The extract-text-webpack-plugin issue was fixed, maybe the fix is similar.
I tried to look at how extract-text-webpack-plugin
got fixed to understand whether a similar pattern can be applied to expose-loader
. But honestly, I have no idea. I hope someone that is familiar with either can send a patch PR soon.
Actually the problem expose-loader
encountering might be different from what extract-text-webpack-plugin
is having (based on webpack-contrib/extract-text-webpack-plugin#648 (comment) ).
So a patch to webpack/webpack
(as described at webpack/webpack#4613 (comment) ) "fixes" this issue. But I think such a patch would also mess up with the consistent hashing for long-term caching since for the modules skipped hashing would be non-deterministic (I think). But I am not sure. I am hoping @sokra would weigh in.
just saw this after opening #58 sorry for that :P.
The issue probably should be handled by webpack?
probably modules created in the pitch phase should by default get a new userRequest
@timse thanks for #58 ! That would at least unblock everyone while the underlying issue gets fixed at https://github.com/webpack/webpack .
Module build failed: TypeError: this.query.substr is not a function
at Object.module.exports.pitch (...\node_modules\expose-loader\index.js:43:34)
What about this message?