Skip to content

feat(nestjs): add CJS output for CommonJS NestJS projects#39

Open
CaioCesarPS wants to merge 1 commit into
pontusab:mainfrom
CaioCesarPS:feat/nestjs-cjs-compat
Open

feat(nestjs): add CJS output for CommonJS NestJS projects#39
CaioCesarPS wants to merge 1 commit into
pontusab:mainfrom
CaioCesarPS:feat/nestjs-cjs-compat

Conversation

@CaioCesarPS

Copy link
Copy Markdown

What

Add a CommonJS build (dist/index.cjs) to @getworkbench/nestjs by enabling the cjs format in tsup and adding a require condition to the exports field.

Why

NestJS projects use "module": "commonjs" in tsconfig.json by default. With the package being ESM-only, any standard NestJS app importing @getworkbench/nestjs would crash at startup with:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in .../node_modules/@getworkbench/nestjs/package.json

This happens because TypeScript with "module": "commonjs" compiles import statements (including dynamic import()) to require(), which cannot load ESM-only packages.

Adding "cjs" to the tsup format array emits dist/index.cjs alongside the existing dist/index.js. The require condition in exports then routes CommonJS consumers to the CJS build while ESM consumers continue using the existing dist/index.js.

Checklist

  • Typecheck passes (bun run typecheck)
  • Lint passes (bun run lint)
  • Build passes (bun run build)
  • CHANGELOG.md updated if this affects users

…rojects

NestJS uses "module": "commonjs" by default. The package was ESM-only,
causing ERR_PACKAGE_PATH_NOT_EXPORTED whenever a standard NestJS app
tried to import it.

- Add "cjs" to tsup formats so dist/index.cjs is emitted on build
- Add "require": "./dist/index.cjs" condition to the exports field
@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

@CaioCesarPS is attempting to deploy a commit to the Pontus Abrahamsson's projects Team on Vercel.

A member of the Team first needs to authorize it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant