Skip to content

fix(hooks): switch build to tsup for ESM compatibility#202

Closed
cameronapak wants to merge 3 commits intoyouversion:mainfrom
cameronapak:fix/hooks-esm-compat
Closed

fix(hooks): switch build to tsup for ESM compatibility#202
cameronapak wants to merge 3 commits intoyouversion:mainfrom
cameronapak:fix/hooks-esm-compat

Conversation

@cameronapak
Copy link
Copy Markdown
Collaborator

Problem

The hooks package uses raw tsc to compile, which copies import specifiers verbatim — e.g. export * from './useBook' in the source becomes the same extensionless import in dist/index.js. Since the package declares "type": "module", strict ESM runtimes (Deno, Val Town) fail with:

Cannot find module '.../dist/useBook'
Did you mean to import with the ".js" extension?

This only affects hooks — core and ui already use tsup, which bundles everything into a single file (no relative imports survive in the output).

Fix

Switch hooks to tsup, matching the build strategy of core and ui:

  • build and dev scripts now use tsup src/index.ts --format cjs,esm --dts
  • tsconfig.build.json updated to emitDeclarationOnly (tsup handles JS output)
  • Adds proper CJS support (dist/index.cjs) via dual format output
  • tsup added to devDependencies (same version as core/ui: 8.5.0)

What changes

File Change
packages/hooks/package.json Updated scripts, exports, added tsup
packages/hooks/tsconfig.build.json Scoped to declaration-only emit

No source code changes. No API changes. The published package exports remain identical.

The hooks package was using raw tsc to compile, which copies import
specifiers verbatim without adding .js extensions. This breaks in
strict ESM runtimes like Deno that require explicit file extensions
on relative imports.

Switch to tsup (matching core and ui packages) which bundles all
modules into a single output file, eliminating extensionless relative
imports entirely. Also adds proper CJS support via dual format output.
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 26, 2026

⚠️ No Changeset found

Latest commit: 35f111b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 26, 2026

Greptile Summary

Review completed and submitted via submit_review tool.

Confidence Score: 4/5

Safe to merge after addressing the missing --dts flag in the dev watch script; production builds are correct.

The fix is well-targeted and the production build output (both JS artifacts and type declarations) is correct. The only concrete issue is the dev watch script not regenerating .d.ts files, which affects monorepo development DX but not published artifacts.

packages/hooks/package.json — dev script line 25 needs --dts to keep types fresh during watch

Reviews (5): Last reviewed commit: "Updated pnpm-lock.yaml" | Re-trigger Greptile

substrate-bot added 2 commits March 26, 2026 17:10
Split build into build:js (tsup) and build:types (tsc -p tsconfig.build.json)
so that tsconfig.build.json declarations settings actually take effect.
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.

1 participant