Skip to content

dist/cjs is loaded as ESM because of "type": "module", so all require exports fail #124

Open

Description

@trackoor

package.json sets "type": "module", while "main" and every "require" condition in "exports" point to .js files under dist/cjs/ without a dist/cjs/package.json ({"type": "commonjs"}) or .cjs extension, so Node parses the CommonJS output as ES modules.

Save as repro.cjs and run npm install react-datocms@8.1.2 react react-dom && node repro.cjs:

const { toNextMetadata } = require("react-datocms/seo");

Actual output:

file:///.../node_modules/react-datocms/dist/cjs/Seo/index.js:16
Object.defineProperty(exports, "__esModule", { value: true });
                      ^

ReferenceError: exports is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '.../node_modules/react-datocms/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

The same error occurs for require("react-datocms") and all 11 subpath exports (./seo, ./image, ./rsc-image, ./video-player, ./structured-text, ./use-query-subscription, ./use-site-search, ./use-video-player, ./use-content-link, ./content-link, ./stega). ESM import resolves to dist/esm and works.

Expected output: require("react-datocms/seo") and the other "require" entry points load dist/cjs as CommonJS without throwing. Writing {"type": "commonjs"} to dist/cjs/package.json after tsc:cjs makes all 12 entry points load cleanly.

Versions tested: react-datocms@8.1.2 (npm latest) and master (759b5b404), Node.js v26.13.0 and v24.22.2.

Credit: https://ucsbplse.github.io/

Activity

  1. roger-datocms commented on Nov 16, 2026

    @roger-datocms
    Member

    Thank you for this report! I'll try to get it fixed in #125

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions