webpack: __webpack_require__.d is not a function

Bug report

What is the current behavior?

I have a big/medium sized project using webpack 5.36.2. just migrated from webpack 4.44.2. which worked fine for my team but the speed improvement between those two versions is just insane. Thank you for that. I noticed that optimization.runtimeChunk = true gave an extra performance boost, but the resulting bundle shows an error “webpack_require.d is not a function” which seams to happen just in that project. i tried to isolate the error in a small test repo. if i set optimization.runtimeChunk = false then the error disappears, but the build time is significantly higher. sometimes its “webpack_require.r is not a function”.

If the current behavior is a bug, please provide the steps to reproduce.

  1. clone this repo https://github.com/code1x1/webpack-require-d-is-not-a-function
  2. run npm run start
  3. open http://localhost:3000 in your browser
  4. open developer console in your browser

What is the expected behavior?

optimization.runtimeChunk = true should build the bundle and the runtime.~chunk.js should contain webpack_require.d definition which is missing.

Other relevant information: webpack version: 5.36.2 Node.js version: v12.16.3 Operating System: Debian GNU/Linux 10 (buster) Additional tools: npm 6.14.12

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 15 (7 by maintainers)

Most upvoted comments

Change runtimeChunk: 'true' on ``runtimeChunk: ‘single’, also you need webpack-dev-server@4-beta.3` with options:

devServer: {
        open: false,
        hot: false,
        onListening: (server) => {
            console.log('Listening on address:', server.server.address());
        },
        historyApiFallback: true,
        firewall: [
            'localhost',
            'localhost:3000'
        ],
        static: path.resolve(__dirname, '..', './app'),
        host: '0.0.0.0',
        public: 'http://localhost:3000',
        port: 3000
    },

Stable release will be soon, have to respond and it slows down

in webpack v4 we don’t have many optimizations, you can have three variants

  • one entrypoint, here you can use runtimeChunk with any values for better long term cache
  • multiple entrypoints on the same page, here you need set runtimeChunk: 'true', otherwise you will have multiple runtime code
  • multiple entrypoints on different pages, here you can use runtimeChunk with any values for better long term cache too

Don’t forget you can use https://webpack.js.org/configuration/entry-context/#entry-descriptor, in most cases when you want to use multiple entry points and need runtimeChunk: 'true' you want to use dependOn