question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nesting webpack bundle in webpack with externals

See original GitHub issue

Hello, 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.

  1. in the beginning, from line 1, I have the webpack runtime like
    /******/ (function(modules) { // webpackBootstrap
  1. 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 = {};
  1. within this second runtime, react is aliased as var _react = __webpack_require__(3);

  2. this is resolved to 3 like

/* 3 */
    /***/ function(module, exports, __webpack_require__) {

        module.exports = __webpack_require__(11);

    /***/ },
  1. 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:closed
  • Created 8 years ago
  • Reactions:4
  • Comments:18 (12 by maintainers)

github_iconTop GitHub Comments

4reactions
jakeNiemieccommented, Aug 14, 2017

@webpack-bot We still care about this!

0reactions
tutokcommented, Jan 13, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Externals - webpack
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
Webpack externals doesn't seem to work for nested objects.
I was using my webpack externals like this and it works fine. externals: { react: { root: React } }. But now I ......
Read more >
Externals - webpack
The bundle with external dependencies can be used in various module contexts, such as CommonJS, AMD, global and ES2015 modules. The external library...
Read more >
A Guide to Managing Webpack Dependencies - Toptal
A Guide to Managing Webpack Dependencies · Configuring Aliases and Relative Paths · Code Splitting · Extracting Styles Into Separate Bundles · Handling...
Read more >
Micro Frontend Architecture: Import chunks from another ...
However, you can currently only do this from its own build. Webpack doesn't really know how to handle external imports or a chunk...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found