Skip to content

Support CommonJS consumers (CJS) — add dual ESM + CJS build #8

@SwasthK

Description

@SwasthK

Error Message

Error: No "exports" main defined in node_modules/@fly/sprites/package.json
    at exportsNotFound (node:internal/modules/esm/resolve:…)

Cause

The package was ESM-only:

"type": "module",
"exports": {
  ".": {
    "import": "./dist/index.js"
  }
}

No "require" export was provided.
CommonJS runtimes (e.g., Nx/NestJS CJS builds) could not resolve the package.

Steps to Reproduce

  1. Use a CJS backend build (e.g., Nx with "format": ["cjs"])
  2. Install @fly/sprites
  3. Import: import { SpritesClient } from "@fly/sprites";
  4. Build or run backend → Resolution error thrown.

Proposed Solution

Add dual module support:

  • Keep ESM build
  • Add CJS build (dist/index.cjs)
  • Add "require" condition in exports
  • Keep ESM as default
  • No runtime dependencies added

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