Skip to content

fix(jobs): load .ts handlers on Node 26 via --import tsx/esm - #105

Merged
danielheene merged 1 commit into
mainfrom
fix/job-handlers-node26
Oct 9, 2026
Merged

danielheene merged 1 commit into
mainfrom
fix/job-handlers-node26

Conversation

@danielheene

Copy link
Copy Markdown
Owner

Summary

  • Payload's dynamicImport() uses eval('import(...)') to load string handler paths at run time. On Node ≥ 26, tsx's module.register() is deprecated and module.registerHooks() is intentionally nulled out by Payload's bin.js workaround, so no tsx loader is active when the eval'd import fires — Node chokes on the raw .ts files and @/ path aliases.
  • Fix: pass --import tsx/esm (via NODE_OPTIONS in dev/_next/_payload scripts, and directly in start-worker.mjs spawn args) to register tsx as a persistent ESM loader before anything runs.
  • Also pass --disable-transpile to the Payload CLI to skip its own tsx setup, which crashes on Node 26 when tsx is already loaded.

Test plan

  • bun run dev — jobs triggered via the admin panel run without handler import errors
  • node scripts/start-worker.mjs (or worker container) — heartbeat ping and other scheduled jobs execute
  • bun run migrate / bun run generate:types — Payload CLI commands still work
  • bun run test — all unit tests pass

Payload's dynamicImport() uses eval('import(...)') to hide handler path
imports from bundler static analysis. On Node ≥ 26, tsx's module.register()
is deprecated and module.registerHooks() is broken when loaded through
Payload's bin.js tsImport() call — so no tsx loader is active when the
eval'd import fires, and Node chokes on the raw .ts files.

Fix: register tsx as a persistent ESM loader upfront via --import tsx/esm
in NODE_OPTIONS (dev, _next, _payload) and in start-worker.mjs's spawn
args. Combined with --disable-transpile on the Payload CLI, this skips
bin.js's own tsx setup (which crashes on Node 26 when tsx is already
loaded) and lets all eval'd dynamic imports resolve .ts files and @/ aliases.
@danielheene
danielheene merged commit 409b554 into main Oct 9, 2026
6 of 7 checks passed
@danielheene
danielheene deleted the fix/job-handlers-node26 branch October 9, 2026 09:05
danielheene-website-release Bot pushed a commit that referenced this pull request Oct 9, 2026
## [1.12.1](v1.12.0...v1.12.1) (2026-10-09)

### Bug Fixes

* **jobs:** load .ts handlers on Node 26 via --import tsx/esm ([#105](#105)) ([409b554](409b554))
@danielheene-website-release

Copy link
Copy Markdown

🎉 This PR is included in version 1.12.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

This branch was successfully deployed

1 active deployment
Testing — ceac0f79 Deployed Oct 9, 2026 by danielheene via CI / E2E Tests #75
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant