-
Notifications
You must be signed in to change notification settings - Fork 1
Subpath exports missing 'types' condition for moduleResolution: node #113
Copy link
Copy link
Closed
Description
Description
The docxodus/react subpath export works at runtime via bundlers (Vite, webpack) that understand package.json "exports", but fails TypeScript compilation when tsconfig.json uses "moduleResolution": "node" (the most common setting in existing projects).
Error
error TS2307: Cannot find module 'docxodus/react' or its corresponding type declarations.
There are types at '/path/to/node_modules/docxodus/dist/react.d.ts', but this result
could not be resolved under your current 'moduleResolution' setting. Consider updating
to 'node16', 'nodenext', or 'bundler'.
Root Cause
In package.json, the "./react" export only has "import" and "types" conditions:
{
"exports": {
"./react": {
"import": "./dist/react.js",
"types": "./dist/react.d.ts"
}
}
}With "moduleResolution": "node", TypeScript ignores the "exports" field entirely and falls back to looking for docxodus/react.d.ts or docxodus/react/index.d.ts at the package root — neither exists.
Suggested Fix
Add a typesVersions field to package.json, which is respected by all moduleResolution modes:
{
"typesVersions": {
"*": {
"react": ["dist/react.d.ts"],
"worker": ["dist/worker.d.ts"],
"pagination": ["dist/pagination.d.ts"]
}
}
}This makes import { PaginatedDocument } from "docxodus/react" resolve types correctly regardless of moduleResolution setting.
Current Workaround
// @ts-expect-error -- tsconfig uses moduleResolution:"node" which doesn't
// support package.json "exports" subpaths. The import works at runtime via Vite.
import { PaginatedDocument } from "docxodus/react";Environment
- docxodus: 5.5.2
- TypeScript: 5.x
- tsconfig
moduleResolution:"node"
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels