fix: route CJS consumers to CJS declarations#852
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@claude review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
import/requireconditions with declaration files that match the runtime module kind../dist/index.d.ctsfiles while keeping ESM consumers on./dist/index.d.ts.Root Cause
The packages publish CJS runtime entrypoints via
require, butexports["."].typesalways pointed TypeScript at./dist/index.d.ts. Because these packages aretype: "module", Node16/NodeNext CommonJS consumers resolved a CJS runtime file with an ESM declaration file, triggering TS1479/ATTW "Masquerading as ESM" failures.Tsup already emits matching
.d.ctsdeclarations; they were just unreachable from the package export maps.Refs LFE-10565 and langfuse/langfuse#14640.
Validation
corepack pnpm test:unit -- package-exportscorepack pnpm format:checkcorepack pnpm typecheckcorepack pnpm lintPATH=/Users/hassieb/.nvm/versions/node/v24.14.0/bin:$PATH corepack pnpm buildPATH=/Users/hassieb/.nvm/versions/node/v24.14.0/bin:$PATH corepack pnpm dlx @arethetypeswrong/cli --pack packages/core --format table --no-emoji --no-colorPATH=/Users/hassieb/.nvm/versions/node/v24.14.0/bin:$PATH corepack pnpm dlx @arethetypeswrong/cli --pack packages/langchain --format table --no-emoji --no-color@langfuse/coretarball in a CJS project withmodule: "node16"andmoduleResolution: "node16"; both value and type-only imports passtsc --noEmit.check:lint,check:type, andcheck:format.Greptile Summary
This PR fixes a TypeScript type-resolution bug where CJS consumers using
moduleResolution: "node16"or"nodenext"were being directed to ESM declaration files (.d.ts), triggering TS1479 "Masquerading as ESM" errors. The fix restructures theexportsmap in all eight published packages from a flattypes/import/requireshape to nestedimportandrequireconditions, each carrying its own matchingtypespointer.package.jsonfiles are updated consistently:requirenow points TypeScript at./dist/index.d.ctswhileimportkeeps./dist/index.d.ts. Thetypescondition is correctly ordered first in each block, which TypeScript requires when evaluating conditions.tests/unit/package-exports.test.ts) asserts the exact structure and key ordering of every package's export map, providing a regression guard for future edits.Confidence Score: 5/5
Safe to merge; the change is mechanically consistent across all eight packages and has been validated with ATTW, tsc, and the new unit test.
The restructured export maps are applied identically to all eight packages, the types condition is correctly ordered before default in both blocks, and the top-level types fallback remains for older TypeScript versions. The new unit test locks down key ordering so future edits cannot silently regress back to the broken shape. No logic errors or missing cases found.
No files require special attention; the changes are uniform boilerplate and the test covers all packages.
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD Consumer[TypeScript Consumer] Consumer -->|moduleResolution: node16/nodenext| ExportMap["package.json exports['.']"] ExportMap -->|ESM import| ImportBlock["import condition"] ExportMap -->|CJS require| RequireBlock["require condition"] ImportBlock --> ImportTypes["types: ./dist/index.d.ts (ESM declaration)"] ImportBlock --> ImportDefault["default: ./dist/index.mjs (ESM runtime)"] RequireBlock --> RequireTypes["types: ./dist/index.d.cts (CJS declaration) - Fixed"] RequireBlock --> RequireDefault["default: ./dist/index.cjs (CJS runtime)"] style RequireTypes fill:#90EE90 style ImportTypes fill:#90EE90%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% flowchart TD Consumer[TypeScript Consumer] Consumer -->|moduleResolution: node16/nodenext| ExportMap["package.json exports['.']"] ExportMap -->|ESM import| ImportBlock["import condition"] ExportMap -->|CJS require| RequireBlock["require condition"] ImportBlock --> ImportTypes["types: ./dist/index.d.ts (ESM declaration)"] ImportBlock --> ImportDefault["default: ./dist/index.mjs (ESM runtime)"] RequireBlock --> RequireTypes["types: ./dist/index.d.cts (CJS declaration) - Fixed"] RequireBlock --> RequireDefault["default: ./dist/index.cjs (CJS runtime)"] style RequireTypes fill:#90EE90 style ImportTypes fill:#90EE90Reviews (1): Last reviewed commit: "psuh" | Re-trigger Greptile