Skip to content

Fix webpack 5 browser builds - #548

Merged
rosston merged 1 commit into
mainfrom
fix-531-webpack-module
Oct 12, 2026
Merged

rosston merged 1 commit into
mainfrom
fix-531-webpack-module

Conversation

@rosston

@rosston rosston commented Oct 12, 2026

Copy link
Copy Markdown
Member

Fixes #531

Since 3.20.1, src/replace/index.js always imported can-register-loader, which requires Node's module. webpack 5 doesn't polyfill core modules, so every browser build failed with "Can't resolve 'module'".

Move the loader check into src/replace/module/index.js, which the browser field already swaps out. The check still throws synchronously. Replace the store's events EventEmitter with a plain array, since events isn't a dependency and only resolved when something else installed it.

Give the browser stubs a Node.js-only error for td.replaceEsm() and a listMockedModules() that returns [], so neither fails with a TypeError.

Restore a webpack example that bundles both entry points for the web, runs them, and fails if a Node core module or a polyfill of one ends up in the bundle. Remove the test:example:plain-html script, whose example was deleted in 0825a6a.

Fixes #531

Since 3.20.1, src/replace/index.js always imported can-register-loader,
which requires Node's `module`. webpack 5 doesn't polyfill core modules,
so every browser build failed with "Can't resolve 'module'".

Move the loader check into src/replace/module/index.js, which the
`browser` field already swaps out. The check still throws synchronously.
Replace the store's `events` EventEmitter with a plain array, since
`events` isn't a dependency and only resolved when something else
installed it.

Give the browser stubs a Node.js-only error for td.replaceEsm() and a
listMockedModules() that returns [], so neither fails with a TypeError.

Restore a webpack example that bundles both entry points for the web,
runs them, and fails if a Node core module or a polyfill of one ends up
in the bundle. Remove the test:example:plain-html script, whose example
was deleted in 0825a6a.
@rosston rosston self-assigned this Oct 12, 2026
@rosston
rosston marked this pull request as ready for review October 12, 2026 16:06
@rosston
rosston merged commit ec31f1b into main Oct 12, 2026
12 checks passed
@rosston
rosston deleted the fix-531-webpack-module branch October 12, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Module not found: Error: Can't resolve 'module' in 'node_modules/testdouble/lib'

1 participant