Skip to content

@analytics/core: require("@analytics/core/client") fails because dist/client/core.js is CommonJS under "type": "module" #526

Open

Description

@trackoor

require("@analytics/core/client") throws in Node.js because packages/analytics-core/package.json sets "type": "module" while exports["./client"].require points to ./dist/client/core.js, which is a CommonJS bundle.

repro.cjs:

console.log("root:", typeof require("@analytics/core").Analytics);
console.log("client:", typeof require("@analytics/core/client").Analytics);

Run:

npm install @analytics/core@0.13.2
node repro.cjs

Actual output:

root: function
...
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '.../node_modules/@analytics/core/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

(import { Analytics } from "@analytics/core/client" works because exports["./client"].import resolves to ./dist/client/core.module.js.)

Expected output:

root: function
client: function

packages/analytics-core/server/package.json renames its CommonJS output to analytics-core.cjs for exports["."].require (follow-up to #501), whereas client/package.json leaves ./dist/client/core.js with a .js extension (and packages/analytics-core/package.json "files" only lists dist/**/*.js, so dist/**/*.cjs is also needed for dist/client/core.cjs to be included in the published tarball).

Tested on @analytics/core@0.13.2 (npm latest) and master (6a5b895) with Node.js v26.13.0 and v24.22.2.

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

Activity

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