From 94eb2ff5b4b0521096cfa1f201d1cdf3d5d0f1ea Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Mon, 20 Apr 2026 01:06:09 -0400 Subject: [PATCH] fix: set module.exports = Slider for Node ESM-for-CJS default-import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set `module.exports` (and `module.exports.default`) to the `Slider` class directly from `src/index.js`, so the compiled `lib/index.js` works under both of the default-import conventions that bundlers use for CJS modules: - Babel-interop path (Rollup, webpack < 5, Vite 7): reads `exports.default`, which we still set via the explicit `module.exports.default = Slider` assignment. - Node ESM-for-CJS path (Vite 8 / rolldown, webpack 5, Node's own ESM-importing-CJS): reads `module.exports`, which is the `Slider` class itself — not a `{default: Slider, __esModule: true}` namespace object. Before this change the compiled entry was `exports.default = _slider.default; exports.__esModule = true;` with no `module.exports` reassignment, so consumers on the Node ESM-for-CJS path received the full namespace as their default import and `` crashed with `Element type is invalid: ... got: object` (React error #130) when bundled by Vite 8. Closes #2444. References: - https://github.com/rolldown/rolldown/issues/8061 (rolldown's isNodeMode heuristic that triggers the path split) - https://rolldown.rs/in-depth/bundling-cjs#ambiguous-default-import-from-cjs-modules --- src/index.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 66ae78948..a4ab9a0cd 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,23 @@ +// Expose Slider as the CJS `module.exports` directly so the compiled entry +// works under both of the default-import conventions that bundlers use for +// CJS modules: +// +// - The Babel-interop path used by Rollup, webpack < 5, Vite 7, and bundlers +// that honor `__esModule: true`: reads `exports.default`, which we still +// set via the explicit `.default` assignment below. +// - The Node ESM-for-CJS path used by Vite 8 (rolldown), webpack 5, and Node +// itself when the consumer package has `"type": "module"`: reads +// `module.exports`, which is the Slider class itself — *not* a +// `{default: Slider, __esModule: true}` namespace object. +// +// Without the `module.exports = Slider` line, the compiled lib/index.js emits +// `exports.default = Slider; exports.__esModule = true;` and leaves +// `module.exports` as the full `exports` object, so consumers on the Node +// ESM-for-CJS path receive that namespace and `` crashes with +// `Element type is invalid: ... got: object` (React error #130). +// See https://github.com/rolldown/rolldown/issues/8061. + import Slider from "./slider"; -export default Slider; +module.exports = Slider; +module.exports.default = Slider;