Skip to content

Fix Optional Dependencies & CJS - #63

Merged
praisethemoon merged 5 commits into
mainfrom
sch/optional-deps-fix
Sep 24, 2026
Merged

praisethemoon merged 5 commits into
mainfrom
sch/optional-deps-fix

Conversation

@praisethemoon

@praisethemoon praisethemoon commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #58: @tanstack/react-table was declared an optional peer dependency but never was.
src/extra.ts re-exported DataTable, and Rollup resolves re-exported modules
whether or not their exports are used — so every consumer of baukasten-ui or
baukasten-ui/extra had to have it installed. Without it, production builds
failed with MISSING_EXPORT, dev served a stub that threw on page load, and
tsc only passed because skipLibCheck hid the unresolved imports.

DataTable now has its own entry point and is no longer in the root or extra
barrels.

Breaking Changes

- import { DataTable } from 'baukasten-ui';
+ import { DataTable } from 'baukasten-ui/data-table';

Moving with it: createSelectColumn, useDataTable, useDataTableData,
applyDataTransaction, mergeTransactions, and the types ColumnDef,
SortingState, PaginationState, RowSelectionState, ColumnResizeMode,
Row. Examples, the website DataTable page and the write-baukasten skill are
updated in this PR.

Also fixed

Two unrelated packaging bugs found while verifying, both present since the
initial commit:

  • baukasten-ui/styles never existed. Declared in exports and documented
    as a public entry point, but there was no styles build entry, so it failed
    for every consumer. Removed rather than built — baukasten-ui/core already
    re-exports all of it.
  • require() was broken on every entry. "type": "module" plus CJS entries
    named .js meant Node parsed the CommonJS build as ESM and died with
    ReferenceError: exports is not defined. Entries now emit .cjs.

Risk level:

  • Low risk (docs, tests, minor fixes)
  • Medium risk (above average work, refactors)
  • High risk (infra, critical changes)

@dhuebner dhuebner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tanstack/react-table was declared an optional peer dependency but was
never optional. src/extra.ts re-exported DataTable, and Rollup resolves
re-exported modules whether or not their exports are used, so every
consumer of `baukasten-ui` or `baukasten-ui/extra` had to have the package
installed. Without it the production build failed with MISSING_EXPORT, dev
served a stub that threw on page load, and tsc only passed because
skipLibCheck hid the eight unresolved imports in the .d.ts.

DataTable now lives at `baukasten-ui/data-table` and is no longer exported
from `extra` or the root barrel. Nothing reachable from `.`, `./core` or
`./extra` touches react-table, so consumers who skip DataTable neither
install nor bundle it.

Measured on a consumer outside the workspace with react-table absent: root,
/core and /extra all build with zero react-table symbols. `{ Avatar }` from
the root entry previously shipped 186,365 bytes gzipped including the whole
table library; it is now 157,496 with none of it. `{ Tabs }` went from
182,825 to 138,690.

Also updates the two LogTable examples, the website DataTable page and its
five code samples, and the write-baukasten skill; adds @tanstack/react-table
to the vscode example and website, which were relying on hoisting.

BREAKING CHANGE: import DataTable from 'baukasten-ui/data-table' rather than
'baukasten-ui' or 'baukasten-ui/extra'. The helpers and types move with it:
createSelectColumn, useDataTable, useDataTableData, applyDataTransaction,
mergeTransactions, ColumnDef, SortingState, PaginationState,
RowSelectionState, ColumnResizeMode and Row.
…built

`exports` declared "./styles" pointing at ./dist/styles.mjs and
./dist/styles.js, and CLAUDE.md listed it as a public entry point, but
vite.config.ts has no `styles` entry and never has — none of the twelve
commits touching that file ever added one, and the subpath has been in
`exports` since the initial commit. Importing it failed with
ERR_MODULE_NOT_FOUND in Node and "Rollup failed to resolve import" in a
bundler. Unlike the CJS entry bug this broke every consumer, not just
`require`; it went unnoticed because nothing in the repo imports it.

Removing rather than building it: src/core.ts already does
`export * from './styles'`, so all 27 value exports and both types (Size,
SizeConfig) are available from baukasten-ui/core. Adding the entry would
have published a second import path to the same tokens and a second copy of
them in consumer bundles.

The path now fails with ERR_PACKAGE_PATH_NOT_EXPORTED, which names the real
problem instead of implying a missing build artifact.
package.json sets "type": "module", which makes Node treat every .js file in
the package as ESM. The CJS build was named .js, so `require('baukasten-ui')`
loaded a CommonJS file, parsed it as ESM, and died on its first statement
with "ReferenceError: exports is not defined". The same applied to /core,
/extra and /data-table.

Vite already named the shared chunks .cjs itself; only the entry files go
through the fileName callback, which is why the output looked correct. The
build has been broken this way since the cjs format was added in 03376c8 —
no commit has ever emitted a .cjs entry or pointed a require condition at one.

Repoints the four require conditions and the legacy `main` field to match.

Verified from a plain CommonJS package outside the workspace: all four
entries now load (root 92 exports, /core 63, /extra 29, /data-table 6), and
ESM imports still resolve.

Known gap: only .d.ts is emitted, no .d.cts, so a CJS consumer on
moduleResolution node16 gets working runtime with ESM-typed declarations
(TS1479). moduleResolution bundler is unaffected. Tracked separately.
The CI format check failed on three files edited earlier here. Both failures
are knock-on effects of content edits: rewriting the Core/Extra criteria row
in CLAUDE.md and removing the DataTable row from the SKILL.md component table
changed the widest cell in each table, so Prettier re-pads every row to the
new width. The third is Prettier normalising *not* to _not_ in datatable.md.

Whitespace only apart from that emphasis marker — `git diff -w` reports zero
content changes in either table. Produced by `npm run format`; `npm run
format:check` now passes.
The vscode-db-explorer example landed on main after this branch was cut,
so it still imported DataTable from the root barrel and relied on a
hoisted @tanstack/react-table. Both break once DataTable moves to its
own entry point.
@praisethemoon
praisethemoon merged commit 1967bac into main Sep 24, 2026
1 check passed
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.

@tanstack/react-table is not actually optional

2 participants