Problem
Various transpilers (like TypeScript) put default exports under the default property when transpiling ESM to CJS.
Meaning:
// mylib (source es)
export default function foo() {};
becomes (roughly):
// mylib (transpiled cjs)
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = foo;
function foo() {};
When consuming such modules, transpilers add "unwrap" helpers (like tslib.__importDefault in TypeScript) to detect the __esModule property in exports and use the default property.
In essence, importing mylib from above like this:
// (source es)
import foo from 'mylib';
will produce the following output (roughly) in TypeScript:
// (transpiled cjs)
const tslib = require('tslib');
const foo = tslib.__importDefault(require('mylib'));
This is not the case with pkgroll, it'll consume mylib without any helpers or checks during bundling.
Please consult the attached repro repository as well as the failing CI showcasing the issue.
Expected behavior
pkgroll uses helpers or detects such cases during bundling to create outputs that handle such cases.
Minimal reproduction URL
https://github.com/enisdenjo/pkgroll-cjs-default-exports-unwrap
Version
v2.5.1
Node.js version
v22.11.0
Package manager
npm
Operating system
macOS
Bugs are expected to be fixed by those affected by it
Compensating engineering work financially will speed up resolution
Problem
Various transpilers (like TypeScript) put default exports under the
defaultproperty when transpiling ESM to CJS.Meaning:
becomes (roughly):
When consuming such modules, transpilers add "unwrap" helpers (like
tslib.__importDefaultin TypeScript) to detect the__esModuleproperty inexportsand use thedefaultproperty.In essence, importing
mylibfrom above like this:will produce the following output (roughly) in TypeScript:
This is not the case with pkgroll, it'll consume
mylibwithout any helpers or checks during bundling.Please consult the attached repro repository as well as the failing CI showcasing the issue.
Expected behavior
pkgroll uses helpers or detects such cases during bundling to create outputs that handle such cases.
Minimal reproduction URL
https://github.com/enisdenjo/pkgroll-cjs-default-exports-unwrap
Version
v2.5.1
Node.js version
v22.11.0
Package manager
npm
Operating system
macOS
Bugs are expected to be fixed by those affected by it
Compensating engineering work financially will speed up resolution