Skip to content

fix: ship CJS .d.cts types for require consumers - #1834

Open
edenbuilds wants to merge 3 commits into
googleapis:mainfrom
edenbuilds:fix/cjs-dual-types-1811
Open

fix: ship CJS .d.cts types for require consumers#1834
edenbuilds wants to merge 3 commits into
googleapis:mainfrom
edenbuilds:fix/cjs-dual-types-1811

Conversation

@edenbuilds

Copy link
Copy Markdown

Summary

  • Nest types under import / require conditions and emit .d.cts companions so TypeScript CJS consumers no longer hit TS1479 while require() already resolves to a working .cjs.
  • Post-build scripts/copy_cjs_types.js copies public .d.ts rollups to .d.cts; files and Rollup export-path resolution updated accordingly.

Test plan

  • A/B: published @google/genai@2.16.0tsc with module: node16 (CJS package) fails TS1479; same tree with nested exports + .d.cts copies → clean.
  • CI / maintainer build verifies node scripts/copy_cjs_types.js after api-extractor.

Fixes #1811

@google-cla

google-cla Bot commented Aug 6, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

TypeScript treats shared .d.ts as ESM when package.json has
"type":"module", so CJS consumers hit TS1479 despite a working
.index.cjs. Nest types under import/require and emit matching .d.cts.

Fixes googleapis#1811
@edenbuilds
edenbuilds force-pushed the fix/cjs-dual-types-1811 branch from 7b966fc to 3b07a34 Compare August 7, 2026 18:38
Update branch with upstream main to clear GitHub BEHIND state.
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.

CJS types missing: require condition has no .d.cts, so TypeScript CommonJS consumers get TS1479 despite the CJS bundle existing

2 participants