Skip to content

migrate:create fails with ENOENT: node:crypto?tsx-namespace=... on Node.js v23.5+ #16949

Closed

Description

@ritesht

Describe the Bug

Summary
Payload 3.85.1 upgraded its internal tsx dependency from 4.21.0 → 4.22.4. [email protected] added support for Node.js's new module.registerHooks() API (introduced in Node.js v23.5.0). On Node.js v23.5+, that new code path has a bug where built-in Node modules (like node:crypto) get a scoped namespace query string appended to their URL (node:crypto?tsx-namespace=1781028172599). Node.js then tries to open that string as a file path, which fails with ENOENT.

[email protected] (used by Payload 3.84.1 and 3.85.0) never used module.registerHooks — it always fell back to the older async module.register() path, which doesn't have this issue.

Root cause (technical)
pn payload migrate:create calls payload/bin.js, which runs:

// payload/bin.js
const { tsImport } = await import('tsx/esm/api')
const { bin } = await tsImport('./dist/bin/index.js', url)
tsImport in tsx/esm/api/index.mjs generates a unique namespace using Date.now() to scope module loading:

// tsx/dist/esm/api/index.mjs
const m = Date.now().toString() // e.g. "1781028172599"
const a = n({ namespace: m }) // registers hooks with this namespace
return p({ namespace: m }).import(r, o) // imports with same namespace
Inside n({ namespace: m }) (the register function), [email protected] checks:

// [email protected] only — this block doesn't exist in [email protected]
const useRegisterHooks =
typeof module.registerHooks === 'function' &&
isFeatureSupported(moduleRegisterHooksCjsReload) &&
!hasTypeScriptPreload

if (useRegisterHooks) {
// Uses module.registerHooks() — the synchronous, in-band hook API
module.registerHooks({ load: createLoadSync(state), resolve: createResolveSync(state) })
}
On Node.js v23.5+, module.registerHooks exists, so tsx uses the new synchronous hook path. These hooks run in-band (same thread, synchronously). During module loading, tsx adds ?tsx-namespace= to resolved file URLs so the scoped hooks know which modules to intercept.

The bug: somewhere in the registerHooks synchronous path, a Node.js built-in module URL (node:crypto) acquires the namespace query parameter (becoming node:crypto?tsx-namespace=1781028172599). The load hook then receives this URL, fails to recognise it as a built-in (the check is URL-prefix based and the query string confuses it), and passes it to the default loader — which tries to open() it as a file → ENOENT.

The older async module.register() path (used by [email protected] and [email protected] on Node.js < v23.5) runs the hooks in a separate worker thread, and this namespace-leaking-to-built-ins problem doesn't occur there.

Link to the code that reproduces this issue

github

Reproduction Steps

Steps to reproduce
Environment:

Node.js v23.5 or higher (confirmed on v25.8.2 and v26.3.0)
Payload 3.85.1 (or any Payload version that pulls [email protected])

1. Create a fresh Payload project

npx create-payload-app@latest my-app
cd my-app

2. Confirm tsx version is 4.22.4

cat node_modules/.pnpm/payload@*/node_modules/tsx/package.json | grep '"version"'

3. Confirm Node.js version is v23.5+

node --version

4. Run any migration command

pnpm payload migrate:create --name test
Expected: Migration file created in src/migrations/.

Actual:

Error: Error creating migration: ENOENT: no such file or directory,
open 'node:crypto?tsx-namespace=1781028172599'
at migrate (.../payload/src/bin/migrate.ts:110:15)
Workaround
Pin tsx to 4.21.0 via pnpm overrides in package.json:

"pnpm": {
"overrides": {
"tsx": "4.21.0"
}
}
Then pnpm install. The migration CLI works correctly because [email protected] doesn't use module.registerHooks and always falls back to the older async module.register() path.

Which area(s) are affected?

area: core

Environment Info

pn payload info

> [email protected] payload XX /projects/xxxxx
> cross-env NODE_OPTIONS=--no-deprecation payload info


Binaries:
  Node: 26.3.0
  npm: 11.16.0
  Yarn: N/A
  pnpm: 10.33.2
Relevant Packages:
  payload: 3.85.1
  next: 16.2.7
  @payloadcms/db-postgres: 3.85.1
  @payloadcms/drizzle: 3.81.0
  @payloadcms/email-nodemailer: 3.85.1
  @payloadcms/graphql: 3.81.0
  @payloadcms/live-preview: 3.81.0
  @payloadcms/live-preview-react: 3.85.1
  @payloadcms/next/utilities: 3.85.1
  @payloadcms/plugin-cloud-storage: 3.85.1
  @payloadcms/plugin-form-builder: 3.85.1
  @payloadcms/plugin-nested-docs: 3.85.1
  @payloadcms/plugin-redirects: 3.85.1
  @payloadcms/plugin-search: 3.85.1
  @payloadcms/plugin-seo: 3.85.1
  @payloadcms/richtext-lexical: 3.85.1
  @payloadcms/storage-s3: 3.85.1
  @payloadcms/translations: 3.81.0
  @payloadcms/ui/shared: 3.85.1
  react: 19.2.7
  react-dom: 19.2.7
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.5.0: Mon Apr 27 20:39:42 PDT 2026; root:xnu-12377.121.6~2/RELEASE_ARM64_T6031
  Available memory (MB): 36864
  Available CPU cores: 14

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Jun 9, 2026
  2. added
    area: core
    and removed
    validate-reproduction
    on Jun 9, 2026
  3. github-actions commented on Jun 9, 2026

    @github-actions
    Contributor

    Please add a reproduction in order for us to be able to investigate.

    Depending on the quality of reproduction steps, this issue may be closed if no reproduction is provided.

    Why was this issue marked with the invalid-reproduction label?

    To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository created with create-payload-app@latest -t blank or a forked/branched version of this repository with tests added (more info in the reproduction-guide).

    To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue. Ensure your reproduction does not depend on secrets, 3rd party registries, private dependencies, or any other data that cannot be made public. Avoid a reproduction including a whole monorepo (unless relevant to the issue). The easier it is to reproduce the issue, the quicker we can help.

    Please test your reproduction against the latest version of Payload to make sure your issue has not already been fixed.

    I added a link, why was it still marked?

    Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.

    Useful Resources

  4. royalswe commented on Jun 9, 2026

    @royalswe

    I got the same issue with latest payload version 3.85.1
    Im on a Apple M1 Pro (Tahoe 26.5.1)
    Node 24.16.0 and 26.0.0

  5. VivienInteractive commented on Jun 10, 2026

    @VivienInteractive

    Hello, Same for me payload version 3.85.1 and node 24.13.1

  6. aufdenpunkt commented on Jun 10, 2026

    @aufdenpunkt

    Hi, same for me.

    Payload version: 3.85.1
    Node version: 24.16.0

  7. smoothdvd commented on Jun 10, 2026

    @smoothdvd

    Claude fixed it with following:

    26 -    "payload": "cross-env NODE_OPTIONS=--no-deprecation payload",
    26 +    "payload": "cross-env NODE_OPTIONS=--no-deprecation payload --use-swc",
    
  8. rgbjoy commented on Jun 13, 2026

    @rgbjoy

    Same error

    node v26.3.0
    payload 3.85.1

  9. oxidia commented on Jun 16, 2026

    @oxidia

    Same issue

    payload version: 3.85.1
    node version: 24.15.0

  10. removed
    status: needs-triage
    on Jun 17, 2026
  11. JorenRothman commented on Jun 18, 2026

    @JorenRothman

    Found a temporary fix for this issue (payload 3.85.1)

    Add this to your package overrides:
    'tsx': '4.19.4'

    for example pnpm-workspace.yaml

    overrides:
        'tsx': '4.19.4'
    
  12. Vovcharaa commented on Jun 19, 2026

    @Vovcharaa

    Same here with:
    payload: 3.85.1
    tsx: 4.22.4
    node: v24.16.0

    Codex did this import before running payload to mitigate issue:

    import Module from 'node:module'
    
    Module.registerHooks = undefined
    
  13. jliguori1312 commented on Jun 21, 2026

    @jliguori1312

    Same issue here, payload 3.85.1, tsx 4.22.4 and node 24.14.1.

  14. estevan-ulian commented on Jun 22, 2026

    @estevan-ulian

    That temporary solution worked for me:

    • Delete node_modules
    • Add the following to pnpm-workspace.yaml:
    # ...
    overrides:
      ‘tsx’: '4.19.4'
    • Run pnpm install
    • Run the migration script, in my case pnpm migrate:create 'message'
    • Finally, run pnpm migrate

    My scripts:

    "scripts": {
        // ...
        "payload": "cross-env NODE_OPTIONS=--no-deprecation payload",
        "migrate:create": "pnpm payload migrate:create",
        "migrate": "pnpm payload migrate",
        // ...
      }

    My project info:

    Binaries:
      Node: 24.15.0
      npm: 11.12.1
      Yarn: N/A
      pnpm: 11.0.9
    Relevant Packages:
      payload: 3.85.1
      next: 16.2.9
      @payloadcms/db-postgres: 3.85.1
      @payloadcms/drizzle: 3.85.1
      @payloadcms/email-nodemailer: 3.85.1
      @payloadcms/graphql: 3.85.1
      @payloadcms/next/utilities: 3.85.1
      @payloadcms/plugin-cloud-storage: 3.85.1
      @payloadcms/plugin-seo: 3.85.1
      @payloadcms/richtext-lexical: 3.85.1
      @payloadcms/storage-s3: 3.85.1
      @payloadcms/translations: 3.85.1
      @payloadcms/ui/shared: 3.85.1
      react: 19.2.7
      react-dom: 19.2.7
    Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 25.5.0: Mon Apr 27 20:40:51 PDT 2026; root:xnu-12377.121.6~2/RELEASE_ARM64_T8112
      Available memory (MB): 16384
      Available CPU cores: 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: coreinvalid-reproductionv3

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions