-
-
Notifications
You must be signed in to change notification settings - Fork 613
Closed
Description
- Rollup Plugin Name: @rollup/plugin-commonjs
- Rollup Plugin Version: 21.0.0
Expected Behavior / Situation
If an ESM file is transformed with transformMixedEsModules=true (for require support), it shouldn't replace typeof exports by 'object' and leave it as-is (or replace by 'undefined' ?)
Actual Behavior / Situation
Right now the bundle fails with exports is not defined because of code in ESM such as lodash-es:
https://github.com/lodash/lodash/blob/es/isBuffer.js#L5
var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
// becomes:
var freeExports = exports && !exports.nodeType && exports;(lodash-es itself doesn't require transformMixedEsModules, but other parts of the bundle do)
Modification Proposal
If esModule=true do not transform typeof module/exports/module.exports into 'object', as they'll likely open invalid code paths in an ESM.
(I can PR with tests if agreed)
HoiShan
Metadata
Metadata
Assignees
Labels
No labels