The JSR package ships source that assumes tsup's createRequire banner — @Html('file') crashes at boot on Deno #69

Closed
opened 2026-08-20 18:00:10 +00:00 by chrnx · 0 comments
Owner

@green-tea/core is published on JSR, and JSR serves src/ rather than the tsup build. The ESM build gets a createRequire banner; the source does not. Every lazy require() in src/ therefore has no require on JSR — and one of them is not guarded.

What happens

A Deno app that maps @green-tea/core to jsr:@green-tea/core@26.8.0-beta.1 and calls @Html('public/index.html') dies at boot:

error: Uncaught (in promise) ReferenceError: require is not defined
  const nodePath = require('node:path') as typeof import('node:path');
    at readViewFile (https://jsr.io/@green-tea/core/26.8.0-beta.1/src/views.ts:64:20)
    at buildHtmlTransformer (…/src/views.ts:139:18)
    at createApp (…/src/app/index.ts:187:20)

tsup.config.ts:17 is explicit about why this works everywhere else:

options.banner = { js: "import { createRequire as _createRequire } from 'node:module'; const require = _createRequire(import.meta.url);" };

JSR never runs tsup. deno.json's exports point straight at ./src/index.ts, so the banner the source depends on is not there.

What is affected

Six call sites use the lazy require(), and they fail differently:

Site On JSR Severity
views.ts:64 readViewFile unguarded ReferenceError at boot @Html file and template modes are dead
views.ts:98 buildStaticResolver catch reports "static needs a filesystem and is unavailable on this runtime (edge)" wrong cause — Deno has a filesystem
multipart.ts:71 loadBusboy catch → null → 501 "busboy not installed" wrong cause — it is installed
http/core.ts:34 randomUUID never reached: globalThis.crypto.randomUUID wins safe
ws-adapter.ts:127 loadWebSocketCtor never reached: global WebSocket wins safe
http/server.ts:47 node http never reached: Node-only listen() path safe

So the two that are guarded produce a misdiagnosis rather than a crash, which is worse to debug than the crash: both blame the runtime for a packaging problem, and both name edge while running on Deno.

Why it matters

Publishing to JSR is a deliberate position, stated in deno.json: "a docs example that imports @green-tea/core/bun has to work whichever registry the reader installed from." Right now it does not. The filesystem-backed features are exactly what a JSR reader would reach for on Deno, and they are the ones that break.

Nothing catches this today: the test suite runs against src/ under Vitest on Node, where require exists.

Scope

  • Replace the lazy require() calls with something that works unbuilt. createRequire(import.meta.url) in the source is the same trick the banner performs, and it is Node/Deno/Bun-portable; workerd is the constraint that made these lazy in the first place, so whatever replaces them has to stay unevaluated on the edge path.
  • Add one smoke test that runs an app from the JSR entry points — deno run against deno.json's exports, with @Html('file') and static: true — so this class of "works in the build, not in the source" cannot come back.
  • Until it is fixed, the JSR listing should say which features are unavailable there.

Related

Found while pointing the green-desk demo at JSR instead of npm. The npm package is unaffected — the banner does its job.

`@green-tea/core` is published on JSR, and JSR serves `src/` rather than the tsup build. The ESM build gets a `createRequire` banner; the source does not. Every lazy `require()` in `src/` therefore has no `require` on JSR — and one of them is not guarded. ## What happens A Deno app that maps `@green-tea/core` to `jsr:@green-tea/core@26.8.0-beta.1` and calls `@Html('public/index.html')` dies at boot: ``` error: Uncaught (in promise) ReferenceError: require is not defined const nodePath = require('node:path') as typeof import('node:path'); at readViewFile (https://jsr.io/@green-tea/core/26.8.0-beta.1/src/views.ts:64:20) at buildHtmlTransformer (…/src/views.ts:139:18) at createApp (…/src/app/index.ts:187:20) ``` `tsup.config.ts:17` is explicit about why this works everywhere else: ```js options.banner = { js: "import { createRequire as _createRequire } from 'node:module'; const require = _createRequire(import.meta.url);" }; ``` JSR never runs tsup. `deno.json`'s `exports` point straight at `./src/index.ts`, so the banner the source depends on is not there. ## What is affected Six call sites use the lazy `require()`, and they fail differently: | Site | On JSR | Severity | |---|---|---| | `views.ts:64` `readViewFile` | **unguarded `ReferenceError` at boot** | `@Html` file and template modes are dead | | `views.ts:98` `buildStaticResolver` | `catch` reports *"`static` needs a filesystem and is unavailable on this runtime (edge)"* | wrong cause — Deno **has** a filesystem | | `multipart.ts:71` `loadBusboy` | `catch` → `null` → 501 "busboy not installed" | wrong cause — it is installed | | `http/core.ts:34` `randomUUID` | never reached: `globalThis.crypto.randomUUID` wins | safe | | `ws-adapter.ts:127` `loadWebSocketCtor` | never reached: global `WebSocket` wins | safe | | `http/server.ts:47` node http | never reached: Node-only `listen()` path | safe | So the two that are guarded produce a **misdiagnosis** rather than a crash, which is worse to debug than the crash: both blame the runtime for a packaging problem, and both name `edge` while running on Deno. ## Why it matters Publishing to JSR is a deliberate position, stated in `deno.json`: *"a docs example that imports `@green-tea/core/bun` has to work whichever registry the reader installed from."* Right now it does not. The filesystem-backed features are exactly what a JSR reader would reach for on Deno, and they are the ones that break. Nothing catches this today: the test suite runs against `src/` under Vitest on Node, where `require` exists. ## Scope - Replace the lazy `require()` calls with something that works unbuilt. `createRequire(import.meta.url)` in the source is the same trick the banner performs, and it is Node/Deno/Bun-portable; workerd is the constraint that made these lazy in the first place, so whatever replaces them has to stay unevaluated on the edge path. - Add one smoke test that runs an app **from the JSR entry points** — `deno run` against `deno.json`'s `exports`, with `@Html('file')` and `static: true` — so this class of "works in the build, not in the source" cannot come back. - Until it is fixed, the JSR listing should say which features are unavailable there. ## Related Found while pointing the `green-desk` demo at JSR instead of npm. The npm package is unaffected — the banner does its job.
chrnx closed this issue 2026-09-04 13:32:27 +00:00
Sign in to join this conversation.