Skip to content
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

Setup via webpack.config.js file not working with NamedModulesPlugin #55

Closed
WiseBird opened this issue Oct 18, 2017 · 10 comments · Fixed by #58
Closed

Setup via webpack.config.js file not working with NamedModulesPlugin #55

WiseBird opened this issue Oct 18, 2017 · 10 comments · Fixed by #58

Comments

@WiseBird
Copy link

WiseBird commented Oct 18, 2017

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.

@sokra
Copy link
Member

sokra commented Oct 23, 2017

That's a bug in libIdent webpack/webpack.

@WiseBird
Copy link
Author

@sokra Should I refile it there?

@ypconstante
Copy link

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.

@ypconstante
Copy link

@cansin
Copy link

cansin commented Nov 8, 2017

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.

@cansin
Copy link

cansin commented Nov 8, 2017

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) ).

@cansin
Copy link

cansin commented Nov 10, 2017

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.

@timse
Copy link
Contributor

timse commented Nov 14, 2017

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

@cansin
Copy link

cansin commented Nov 15, 2017

@timse thanks for #58 ! That would at least unblock everyone while the underlying issue gets fixed at https://github.com/webpack/webpack .

@adrielwerlich
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants