From 19b2cc082b14cf9eecc8c2a826e66cd3e6cabb66 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Sat, 9 May 2026 09:20:45 -0400 Subject: [PATCH] Fix main-entry type re-exports failing under bundler resolution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since 0.4.0 the dist/ tree contains both Vite-emitted dist/.js/.cjs files and tsc-emitted dist//index.d.ts folders side by side. With both on disk, TypeScript's `bundler` module resolution prefers the file over the folder, so `dist/index.d.ts`'s `export * from './primitives'` walks into `./primitives.js` (no types) and silently drops every symbol. Net effect: every consumer importing primitives/layout/charts/visualization/ inputs/display/utils/assets/theme symbols from the main entry of ui-kit @>=0.4.0 fails type-check with "Module '@policyengine/ui-kit' has no exported member 'Badge'" (and the same for Skeleton, Container, Button, …). Fix: pin the source re-exports to the explicit `.//index` folder path. TypeScript's bundler resolution then walks into the folder and finds the types. Verified locally with a fresh `tsc --noEmit` against a file:-installed build of this branch. Subpath imports (`@policyengine/ui-kit/primitives`) were unaffected because the `exports` map already pins them to the index.d.ts folder path. No runtime change — Vite's emit and the package's `exports` map are unchanged. Only the .d.ts re-export paths shift. See https://github.com/microsoft/TypeScript/issues/52146 for the upstream ambiguity. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../types-resolution-from-main.fixed.md | 1 + src/index.ts | 28 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) create mode 100644 changelog.d/types-resolution-from-main.fixed.md diff --git a/changelog.d/types-resolution-from-main.fixed.md b/changelog.d/types-resolution-from-main.fixed.md new file mode 100644 index 0000000..9b4b9b8 --- /dev/null +++ b/changelog.d/types-resolution-from-main.fixed.md @@ -0,0 +1 @@ +Main-entry type re-exports now resolve from a TypeScript `bundler` consumer. Since 0.4.0 the dist/ tree contains both Vite-emitted `dist/.js`/`.cjs` files and tsc-emitted `dist//index.d.ts` folders side by side. With both on disk, TypeScript's `bundler` module resolution prefers the file over the folder and reports `Module '"@policyengine/ui-kit"' has no exported member 'Badge'` (and the same for every primitive/layout/charts/visualization/inputs/display/utils/assets symbol) from the main entry. Pinning the source re-exports to the explicit `.//index` folder path forces folder resolution and exposes types correctly. Subpath imports (`@policyengine/ui-kit/primitives`) were unaffected. diff --git a/src/index.ts b/src/index.ts index 2309683..34f909d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,32 +1,40 @@ // Styles — consumers must import '@policyengine/ui-kit/styles.css' separately import './theme/tokens.css'; +// Subpath re-exports use explicit `/index` so the emitted .d.ts resolves +// past the multi-entry `dist/.js` siblings produced by Vite. With both +// `dist/primitives.js` (Vite output) and `dist/primitives/index.d.ts` (tsc +// output) on disk, TypeScript's `bundler` resolution prefers the file over +// the folder and reports "no exported member" from the main entry. Pinning +// the path to `.//index` forces folder resolution and exposes the +// types correctly. See https://github.com/microsoft/TypeScript/issues/52146 + // Runtime tokens (colors, palette, chartColors, typography, …) -export * from './theme'; +export * from './theme/index'; // Types -export * from './types'; +export * from './types/index'; // Utilities -export * from './utils'; +export * from './utils/index'; // Primitives -export * from './primitives'; +export * from './primitives/index'; // Layout -export * from './layout'; +export * from './layout/index'; // Inputs -export * from './inputs'; +export * from './inputs/index'; // Display -export * from './display'; +export * from './display/index'; // Charts -export * from './charts'; +export * from './charts/index'; // Visualization -export * from './visualization'; +export * from './visualization/index'; // Assets -export * from './assets'; +export * from './assets/index';