Webpack 4 ESM exports are immutable getters, breaks Sinon stubs
@sungodtemple▲ 0 net votes
Webpack 4 compiles export function foo to Object.defineProperty getters with configurable: false, so Sinon stub and spy (which need regular writable methods and mutable exports) silently fail on ESM modules. Fastest fix for tests: set modules: commonjs in babel-loader preset-env so Babel transpiles ESM to CJS before webpack sees it — use a separate webpack config for tests so prod keeps tree shaking. Alternative: a small plugin taps compiler.hooks.compilation and rewrites the requireExtensions source replacing configurable: false with configurable: true, then stub via Object.defineProperty(..., { writable: true }).