From ba73d1d5f26a95c458a8be417eec6015bd3f8041 Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Mon, 20 Apr 2026 01:09:33 -0400 Subject: [PATCH] fix: set module.exports = ReactJWPlayer 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 `ReactJWPlayer` class directly from `src/react-jw-player.jsx`, so the compiled `dist/react-jw-player.js` works under both of the default-import conventions that bundlers use for CJS modules: - Babel-interop path (Rollup, webpack < 5, Vite 7): reads `module.exports.default` (or `exports.default`), which we still set via the explicit `module.exports.default = ReactJWPlayer` assignment. - Node ESM-for-CJS path (Vite 8 / rolldown, webpack 5, Node's own ESM-importing-CJS): reads `module.exports`, which is the `ReactJWPlayer` class itself — not a `{default: ReactJWPlayer, __esModule: true}` namespace object. Before this change the compiled entry ended with `exports.default = ReactJWPlayer;` + the babel-emitted `Object.defineProperty(exports, "__esModule", {value: 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 #207. 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/react-jw-player.jsx | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/react-jw-player.jsx b/src/react-jw-player.jsx index b458a273..717facd6 100644 --- a/src/react-jw-player.jsx +++ b/src/react-jw-player.jsx @@ -106,4 +106,24 @@ class ReactJWPlayer extends Component { ReactJWPlayer.defaultProps = defaultProps; ReactJWPlayer.displayName = displayName; ReactJWPlayer.propTypes = propTypes; -export default ReactJWPlayer; + +// Expose ReactJWPlayer 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 +// expose via `module.exports.default = ReactJWPlayer` 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 now the ReactJWPlayer class itself — *not* a +// `{default: ReactJWPlayer, __esModule: true}` namespace object. +// +// Without this, the compiled dist/react-jw-player.js emits +// `exports.default = ReactJWPlayer; 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. +module.exports = ReactJWPlayer; +module.exports.default = ReactJWPlayer;