You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
webpack can generate a reference to a module it has optimised out #11536
If webpack sees an ES module that consists merely of
export {};
and tree-shaking is turned on (via sideEffects flag and the presence of a sideEffects property in package.json), then the resulting bundle attempts to initialize that module BUT the module has been optimised out. This produces a bundle that won't load with the error:
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
^
TypeError: Cannot read property 'call' of undefined
at __webpack_require__ (C:\Dev\issue\dist\main.js:20:30)
(Why does TS4.0 generate modules like this? It's because of this commit: microsoft/TypeScript#38696. Without that commit, the resulting module is empty, which seems to make webpack think it's a CJS module, which causes tree-shaking to go awry and bundle sizes to explode. We have 35 such modules in our codebase, as they occur when you have TypeScript files that contain only type information and no concrete code.)
If the current behavior is a bug, please provide the steps to reproduce.
contains a tiny amount of TypeScript code that gets compiled to plain ES modules
bundles up those ES modules using a tiny webpack config with no loaders
runs the bundle, which fails
What is the expected behavior?
Webpack has removed the module but kept the reference to it. It could keep the module so the reference works, or, preferably, remove the reference if it has correctly established that the module is redundant.
Other relevant information:
webpack version: 4.44.2
Node.js version: 10.15.1 / 12.18.3
Operating System: Windows 10 / Linux
Additional tools:
Yup, will try to get some time. I've lost a lot of time over the last few weeks upgrading to Emotion 11, TS3.9, TS4.0 and latest eslint, all of which have had significant breaking changes, but I'll give it a go.
Activity
alexander-akait commentedon Sep 28, 2020
Solved in webpack@5, can you try?
RoystonS commentedon Sep 28, 2020
Yup, will try to get some time. I've lost a lot of time over the last few weeks upgrading to Emotion 11, TS3.9, TS4.0 and latest eslint, all of which have had significant breaking changes, but I'll give it a go.
RoystonS commentedon Sep 28, 2020
I've not been able to try it on our main codebase as we have a few loaders that are specifying "webpack@^3 || ^4" so they're bound to cause trouble.
But I have tried it on the above repro repository, and it does indeed work with webpack 5rc1 there.
https://github.com/RoystonS/webpack-sideeffect-issue/tree/webpack5
alexander-akait commentedon Sep 28, 2020
Let's close, because fixed, feel free to update loader to support webpack@5 and update your code base, feel free to feedback