Skip to content

fix(build): use full relative paths in emitted type declarations - #1327

Merged
XOP merged 3 commits into
ClickHouse:mainfrom
kuttyhub:fix/dts-relative-import-extensions
Nov 27, 2026
Merged

XOP merged 3 commits into
ClickHouse:mainfrom
kuttyhub:fix/dts-relative-import-extensions

Conversation

@kuttyhub

@kuttyhub kuttyhub commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • vite-plugin-dts copies extensionless relative specifiers from src/ into dist/types. Because the package is "type": "module", TypeScript treats those .d.ts files as ESM under moduleResolution: "node16" / "nodenext" and can't resolve them, so exports silently become any.
  • beforeWriteFile now rewrites each relative specifier to ./Foo.js or ./Foo/index.js. It checks the matching src/ path to tell files from directories, and leaves package imports and anything it can't match alone.
  • Added unit tests for the rewrite in plugins/dts-import-extensions.test.ts.

Links and tickets

Fixes #1310

Good to know

Checked against a small consumer ("type": "module", module/moduleResolution: "nodenext") that imports Button, ButtonProps, Pagination, useToast from /hooks and Select from /Select, with deliberate type errors on each:

before after
skipLibCheck: true 0 errors (everything is any) the 5 expected errors
skipLibCheck: false 151 × TS2834, 5 × TS2307 in dist/types no errors from dist/types
moduleResolution: "bundler" resolves still resolves, no new errors

After the build, no relative specifier in dist/types is missing an extension. src/ and the JS output are untouched.

Checklist

  • Breaking changes? (add migration notes in changesets)
  • Visual changes? (specify in changesets)
  • Design review needed?

Contribution

  • Sufficient research before PR
  • Self-reviewed the PR
  • Manually tested the changes (when applies - visual confirmation in Storybook)
  • build works locally (build-storybook not run: no component or story changes)
  • Tests and Stories are aligned with the changes

Note

Low Risk
Build-time .d.ts post-processing only; runtime JS and bundler resolution are unchanged, with behavior covered by unit tests.

Overview
Emitted dist/types declarations now get relative specifiers rewritten to full ESM paths (./Foo.js, ./Foo/index.js) during the vite-plugin-dts write step, fixing TypeScript resolution under moduleResolution: "node16" / "nodenext" where extensionless paths previously turned exports into any.

Adds addDtsImportExtensions in plugins/dts-import-extensions.ts, wired via beforeWriteFile in vite.config.ts using the matching src/ path to choose file vs directory targets; package imports and already-suffixed specifiers are unchanged. Vitest coverage lives in plugins/dts-import-extensions.test.ts. Patch changeset only—no runtime or visual changes for "bundler" consumers.

Reviewed by Cursor Bugbot for commit cdb0789. Bugbot is set up for automated code reviews on this repo. Configure here.

The package is "type": "module", so under moduleResolution node16/nodenext
TypeScript reads dist/types/**/*.d.ts as ESM and needs explicit file paths.
vite-plugin-dts copies the extensionless specifiers from src/, so nearly every
export resolved to `any` (or failed with TS2834 when skipLibCheck is off).

Rewrite relative specifiers in beforeWriteFile to `.js` or `/index.js`,
using the matching src/ path to tell files from directories.

Fixes ClickHouse#1310
@XOP XOP added enhancement New feature or request infra CI, workflows, scripts labels Nov 25, 2026
Vitest's jsdom environment resolved the bare 'path' import to the npm
'path' polyfill, which calls util.isString, removed in Node 24.
@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cdb0789

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clickhouse/click-ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@workflow-authentication-public

Copy link
Copy Markdown
Contributor

Chromatic Storybook

Check Status Link
Storybook ✅ 672 stories published Open Storybook
UI Tests ✅ 672 tests unchanged Open build

Built from commit: cdb0789283cbe28fd6bd3e019f212470bc8c8c48 · Chromatic run

Statuses as of the end of the run. The build link shows the live review state.

@XOP
XOP requested review from XOP and ariser November 26, 2026 09:32
@XOP
XOP merged commit b96211a into ClickHouse:main Nov 27, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request infra CI, workflows, scripts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Published .d.ts files use extensionless relative imports, resolving exports to any under moduleResolution node16/nodenext

3 participants