fix: bundling compatibility with webpack@5 #2519
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose (TL;DR)
Ensure sinon bundles nicely for browsers without any errors or warnings.
#2411 re-fixed (after "exports" were added I think).
Background
When using webpack v5 to bundle cjs code that calls
require('sinon')
, it would have defaulted to "exports->require" and fail with multiple node API errors/warnings (util, timers, etc.).This patch ensures that anyone who bundles sinon with a bundler that respects "exports" gets the (browser-compatible) esm version.
Tested on both webpack v5 and v4. should be noted that v4 worked even without this patch, as it automatically injected polyfills. webpack@5 no longer does so.
Solution
The esm version bundles without any errors/warnings, so make sure bundlers pick that one up.
How to verify
Use the same steps to reproduce in #2411
Modify the node_modules with this patch and rerun
npx webpack --mode development
Checklist for author
npm run lint
passes