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;