Skip to content

Commit d52e710

Browse files
authored
fix(cycling-coach): inject createRequire into ESM bundle to fix startup crash (#295)
The published binary bundles workspace packages inline (noExternal @enduragent/*), pulling transitive CommonJS deps (@grammyjs/auto-retry -> debug) into the ESM bundle. Their require() of Node builtins hit esbuild's dynamic-require shim, which threw at startup (Dynamic require of "tty" is not supported) — crashing the container and failing the release pack-smoke. Add a createRequire banner so the shim delegates to a real require.
1 parent 6ac56b0 commit d52e710

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"cycling-coach": patch
3+
---
4+
5+
User-facing: Fixed a startup crash that stopped the bot from launching on the latest release.
6+
7+
The published binary bundles workspace packages inline, which pulls in transitive CommonJS dependencies whose `require()` of Node builtins hit esbuild's ESM dynamic-require shim and threw at startup. A `createRequire` banner in the bundle gives that shim a real `require` to delegate to, so the builtins resolve normally.

packages/cycling-coach/tsup.config.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,15 @@ export default defineConfig({
1111
// self-contained. See ADR-0010.
1212
noExternal: [/^@enduragent\//],
1313
// Shebang for the bin field — npm preserves bin permissions on publish.
14-
banner: { js: "#!/usr/bin/env node" },
14+
// createRequire shim: bundling @enduragent/* pulls transitive CJS deps
15+
// (e.g. @grammyjs/auto-retry → debug) inline, and their `require()` of Node
16+
// builtins hits esbuild's ESM `__require`, which throws without a real
17+
// `require` in scope. Defining one makes that shim delegate instead of throw.
18+
banner: {
19+
js: [
20+
"#!/usr/bin/env node",
21+
'import { createRequire as __createRequire } from "node:module";',
22+
"const require = __createRequire(import.meta.url);",
23+
].join("\n"),
24+
},
1525
});

0 commit comments

Comments
 (0)