Skip to content

Commit

Permalink
fix: bundling compatibility with webpack@5 (#2519)
Browse files Browse the repository at this point in the history
* fix: bundling compatibility with webpack@5
when using webpack v5 to bundle code that calls `require('sinon')` (cjs) , it would have defaulted to "exports->require" and fail with multiple node-api requirements (util, timers, etc.)

this patch ensures that anyone who bundles sinon for browser 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.  v5 no longer does so. with this PR, people using webpack@4 to bundle sinon at least see size improvement, as the polyfills are no longer required.

* fix: revert change for package.json -> "browser"
browserify doesn't seem to like esm. leave that entry point alone, and ensure "exports" -> "browser" (which webpack@5 uses) is esm.
  • Loading branch information
AviVahl committed Jun 20, 2023
1 parent b4f868d commit d220c99
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"module": "./pkg/sinon-esm.js",
"exports": {
".": {
"browser": "./pkg/sinon-esm.js",
"require": "./lib/sinon.js",
"import": "./pkg/sinon-esm.js"
},
Expand Down

0 comments on commit d220c99

Please sign in to comment.