Skip to content

runtime-web/tanstack: browser bundling fails — root barrel transitively imports node:url (fileURLToPath) #287

Closed

Description

@dmealing

Summary

@metaobjectsdev/runtime-web and @metaobjectsdev/tanstack cannot be bundled for a browser. Importing anything from either root barrel pulls in @metaobjectsdev/metadata's library/library-sources.js, which does import { fileURLToPath } from "node:url" — a Node-only API with no browser equivalent.

Since every generated <Entity>.hooks.ts imports buildFilterQs from @metaobjectsdev/runtime-web and useEntityFetcher from @metaobjectsdev/tanstack, any client consuming the generated TanStack hooks fails to build, unconditionally.

Reproduction

Two lines, no project code:

// probe.ts
import { useEntityFetcher } from "@metaobjectsdev/tanstack";
console.log(useEntityFetcher);
$ bun build probe.ts --target browser

9 | import { fileURLToPath } from "node:url";
           ^
error: Browser polyfill for module "node:url" doesn't have a matching export named "fileURLToPath"
  at node_modules/@metaobjectsdev/runtime-web/node_modules/@metaobjectsdev/metadata/dist/library/library-sources.js:9:10

Versions: @metaobjectsdev/{runtime-web,tanstack,react,codegen-ts-tanstack,codegen-ts-react}@0.21.3, @metaobjectsdev/[email protected], Bun 1.3.14.

Why this looks like an oversight rather than a design choice

@metaobjectsdev/metadata's own root barrel already guards a different Node-only module, with a comment saying exactly why:

// fixture corpora). NODE-ONLY: registry-coverage.ts statically imports node:fs
// ... not in the browser-facing barrel (it would drag node:fs into the root entry, breaking

So the hazard is recognised and handled for registry-coverage, but library/library-sources.js reaches the browser barrel through the same path. It appears to be the same class of bug, one module over.

Note also the nested install: the failing copy is at runtime-web/node_modules/@metaobjectsdev/metadata, not the hoisted one — worth checking whether a version skew between runtime-web's pinned metadata and the top-level one is part of how this slipped through.

Suggested fix

Keep library-sources (and anything else touching node:*) out of the browser-reachable barrel, the same way registry-coverage already is — or split a @metaobjectsdev/metadata/browser entry that the web packages import instead of the root.

Second issue, separable — no grid/column codegen emitted

@metaobjectsdev/codegen-ts-tanstack emits <Entity>.hooks.ts for every entity, but no <Entity>.columns.tsx or .grid.ts for any of them. Tracing it, tanstackGrid() / tanstackGridHook() appear to be opt-in behind a layout.dataGrid metadata node.

If that is intended, it is not discoverable: nothing in the metaobjects-runtime-ui skill or the package description mentions that grids require an additional metadata declaration, and the package description ("emits hooks and column definitions for TanStack Query and Table") implies columns come for free. A line in the skill, or a build-time note when an entity generates hooks but no columns, would have saved a bad assumption. Happy to file separately if you'd prefer.

Context

Reported from an adopting project generating its whole REST surface and client data layer from metadata. The generated server side (routesFileHono + runtime-ts/hono) works well now — 5/5 integration tests green against real Postgres after #286. This is the client half. As with #285/#286, we have not hand-written a substitute or patched locally; reporting instead.

Activity

  1. dmealing commented on Aug 9, 2026

    @dmealing
    MemberAuthor

    Fixed on main in b145e94a — ships in the next release. Your diagnosis was exact, including the registry-coverage comparison: it is the same class of bug, one module over, reaching the barrel via MetaDataLoader instead of directly.

    Fix: a new @metaobjectsdev/metadata/constants subpath — the fifteen pure *-constants.ts modules with no node:* anywhere in the graph. Browser packages import metamodel values from it; types can stay on the root, since import type is erased at build time and drags in no runtime dependency. I took this over inlining the six LAYOUT_* strings because inlining would break the project's own constants discipline. It also gives packages/metadata/src/constants.ts — the location CLAUDE.md has always documented as the home for metamodel constants — a real existence, which it never had.

    Your note about the nested install was a useful steer, though the cause turned out simpler than version skew: there is exactly one value import of metadata in all of client/web, and it was that one. Fixing it severs the chain for both packages.

    The part worth recording — your "why this slipped through" instinct was right, and the mechanism is nastier than it looks. This package's tests run under Bun's test runner, which resolves the "bun" export condition to TypeScript source and never bundles. The failure only exists on the dist path a published consumer resolves, under a browser-targeted bundler. So unit tests could pass forever while the package was unbuildable for its only audience. My first reproduction attempt hit exactly that trap — it took the bun condition, built clean, and told me nothing. I had to redo it against dist to see your error.

    Gated now by a real Bun.build({ target: "browser" }) over the built output, a purity check on the constants barrel, and a live demo asserting that bundling the root barrel still fails — so if the root ever becomes browser-safe, that gets noticed deliberately rather than when someone "simplifies" the import back.

    Verified to reproduce your error verbatim with the fix reverted: Browser polyfill for module "node:url" doesn't have a matching export named "fileURLToPath".

    On the second half — grids. You're right on both counts: tanstackGrid()/tanstackGridHook() are opt-in behind a layout.dataGrid node, and that is not discoverable. The package description does imply columns come for free. No need to file separately, it's tracked here; it's a docs/discoverability gap rather than a defect, so it isn't in this fix. Your suggestion of a build-time note when an entity generates hooks but no columns is the better half of the answer — that's the kind of thing meta gen should say rather than leaving to a skill.

    Thanks again for reporting rather than patching around it. Three for three now (#285, #286, #287), and each one found a gate that couldn't see the thing it was for.

  2. dmealing commented on Aug 9, 2026

    @dmealing
    MemberAuthor

    Both halves fixed and released in 0.21.4.

    The bundling blocker. @metaobjectsdev/metadata's root barrel exports MetaDataLoader → library/library-sources.ts → node:url, so the single value import runtime-web used for buildGrid's LAYOUT_* constants pulled the Node-only loader into every browser bundle. Fixed with a new @metaobjectsdev/metadata/constants subpath — a barrel of pure constant modules with no node:* anywhere in its graph. Browser packages import metamodel values from it; types still come from the root, since import type is erased at build time.

    Now gated by a real Bun.build({ target: "browser" }) over the built dist/ of runtime-web, tanstack, react and angular, plus a purity check on the constants barrel and a live demo that bundling the root barrel still fails. Nothing caught this before because these packages' tests run under Bun's test runner, which resolves the bun export condition to TypeScript source and never bundles — so the suite could pass forever while the published package was unbuildable for its only audience.

    The grid half. You were right that this is separable, and right that it reads as broken codegen. tanstackGrid()/tanstackGridHook() emit only for an entity declaring a layout.dataGrid — intended, but nothing said so, and the package description promised "hooks and column definitions" unconditionally. Rather than only fixing docs (a doc line gets missed the same way this one was), the run now tells you:

    [tanstack-grid] no <Entity>.columns.tsx emitted for Author — grid artifacts are opt-in per entity
    via a `layout.dataGrid` child, and no object in this model declares one. Add e.g.
    {"layout.dataGrid": {"name": "default", "@columns": ["id", "name"]}} to an entity to emit its grid.
    

    It fires only when the generator emitted nothing at all, so it self-extinguishes as soon as any object declares a grid — no permanent nag on a large model.

    Two things surfaced while fixing it, both also in 0.21.4: tanstackGridHook() appeared in no example, which matters because <EntityGrid> is fully controlled (it needs rowCount, a state object and three onChange callbacks) — so the documented tanstackQuery() + tanstackGrid() pair alone left you hand-writing exactly what tanstackGridHook() generates. And a real bug: its filter was missing the TPH clause its sibling has, so a TPH subtype could get a <Sub>.grid.ts whose <Sub>.columns.tsx never exists.

    Docs corrected across the package description, README, docs/ports/typescript-client.md and the metaobjects-runtime-ui agent skill — the old grid example omitted half of <EntityGrid>'s required props and used export names codegen does not produce.

    Thanks for both reports; the second one was the more useful of the two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions