Skip to content

ESM-only exports break CJS consumers — missing "default" or "require" condition #305

@anmol098

Description

@anmol098

Problem

The following packages ship with "type": "module" and only an "import" condition in their exports field:

  • chat
    • @chat-adapter/whatsapp
      • @chat-adapter/shared
        • @chat-adapter/state-memory
          • @chat-adapter/state-redis
            • @resend/chat-sdk-adapter (and its dependency remend)
              This means CJS consumers (projects with "module": "commonjs" in tsconfig) get the following error at runtime:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in .../node_modules/@chat-adapter/whatsapp/package.json

Node's CJS loader looks for a "require" or "default" condition in exports. Since only "import" is present, resolution fails.

Expected

Either:

  1. Add a "default" condition pointing to the same ESM file — Node 22.12+ supports require() of synchronous ESM natively, so "default": "./dist/index.js" is sufficient
    1. Or ship a separate CJS build with a "require" condition

Current workaround

Using pnpm patch to manually add "default": "./dist/index.js" to each package's exports — but this must be re-applied on every version bump.

Environment

  • Node.js v23.11.0
    • pnpm 9.x

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