Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

esm-interop-lab

Tests how different tools handle import thunk from 'redux-thunk' where redux-thunk@2 ships both a CJS build (main: lib/index.js, has __esModule: true) and a native ESM build (module: es/index.js, export default thunk).

Setup

npm install

Results

Bundlers

Script Resolves via is function? how
npm run inspect require() directly - raw shape: {__esModule:true, default:fn}
npm run node main (Node ignores module) no interop
npm run babel main via require() _interopRequireDefault at call site
npm run esbuild:module module (native ESM) no interop needed - real ESM default
npm run esbuild:main main (CJS + __esModule) no interop
npm run webpack:module module (native ESM) no interop needed - real ESM default
npm run webpack:main main (CJS + __esModule) no interop
npm run typescript:cjs main via require() __importDefault at call site
npm run typescript:esm main (NodeNext, no helpers) no interop helpers emitted

Jest

Script Mode Resolves via is function?
npm run jest:cjs CJS (babel-jest) main
npm run jest:esm ESM (--experimental-vm-modules) main
npm run jest:esm:module ESM (--experimental-vm-modules) module 💥

Why jest:esm:module fails

The resolver returns node_modules/redux-thunk/es/index.js via the module field, but Jest's shouldLoadAsEsm() checks the file extension (.js) and the package's "type" field to decide CJS vs ESM. redux-thunk@2 has neither .mjs nor "type": "module", so Jest treats it as CJS and cjs-module-lexer chokes on the export statement.

Run everything

npm run all

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages