fix(migrator): use tsx as runner instead of hook to fix Node.js v22 ESM interop
Some checks are pending
CI / Type Check (push) Waiting to run
CI / Lint (push) Waiting to run
CI / Unit Tests (push) Waiting to run
Deploy / Build & Push Image (push) Waiting to run
Deploy / Deploy to VPS (push) Blocked by required conditions

NODE_OPTIONS="--import tsx/esm" registers tsx as a hook, which exposes the
tsx@4.21.0 + Node.js v22 importSyncForRequire bug (named export not found).
Running tsx directly as the process runner handles TypeScript module loading
at a higher level, avoiding the CJS/ESM interop conflict.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Vadym Samoilenko 2026-05-13 20:00:39 +01:00
parent cff1baa871
commit a26a9c05ae

View file

@ -1,8 +1,7 @@
# syntax=docker/dockerfile:1
# Migrator image — runs `payload migrate` / `payload migrate:create`
# Requires node:22 for pnpm 11 (node:sqlite).
# tsx 4.x ESM loader must be preloaded via NODE_OPTIONS so bare
# specifiers (.ts extensions) resolve before any module is imported.
# tsx is used as the RUNNER (not as a hook) to avoid the Node.js v22
# importSyncForRequire bug that breaks --import tsx/esm hook mode.
FROM node:22-alpine AS base
RUN corepack enable && corepack prepare pnpm@latest --activate
@ -13,6 +12,5 @@ RUN pnpm install --frozen-lockfile
COPY . .
ENV NODE_OPTIONS="--import tsx/esm"
ENTRYPOINT ["pnpm", "payload"]
CMD ["migrate"]
ENTRYPOINT ["pnpm", "exec", "tsx"]
CMD ["node_modules/payload/bin.js", "migrate"]