nesting webpack bundle in webpack with externals
See original GitHub issueHello,
I am trying to use webpack
to bundle a node module, which may later use by an app at client side (so, use webpack again to target the browser environment).
My node package is simply some reusable react components.To avoid bundling all the dependencies (like react
), I am following these 3 posts by jlongster. With that, my backend.js file has all the react import is replaced with
`var _react = __webpack_require__(3);`
where module 3 is
/* 3 */
/***/ function(module, exports, __webpack_require__) {
module.exports = require("react");
/***/ },
so far everything is good.
Now I am importing above package (Say MyComp) in to a react application. Webpack builds a bundle, client.js, which has these in it.
- in the beginning, from line 1, I have the webpack runtime like
/******/ (function(modules) { // webpackBootstrap
- then the imported
MyComp
also wrapped along with its runtime as
/* 103 */
/***/ function(module, exports, __webpack_require__) {
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
-
within this second runtime, react is aliased as
var _react = __webpack_require__(3);
-
this is resolved to 3 like
/* 3 */
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(11);
/***/ },
- but, 11 within this second runtime is
/* 11 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
var React = __webpack_require__(3);
var WindowListenable = __webpack_require__(24);
it is not react
!! . But is react
outside/main runtime (from the client bundler).
so I get error like
Uncaught TypeError: React.createClass is not a function
(anonymous function) @ index.js:8553__webpack_require__ @ index.js:20
so, anyway get rid of the run time if the build target is node, or anything to make the resolution work correctly.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:4
- Comments:18 (12 by maintainers)
@webpack-bot We still care about this!
Hi @alexander-akait, I am trying to migrate a project from v4 to v5, and I experienced exactly the same issue. In v4 everything works fine. I am not sure if it is a case but it happens only for
@apollo/client
dependency, e.g.react
is handled correctly