Skip to content

Chained loaders can break each other with ERR_METHOD_NOT_IMPLEMENTED #59998

@bengl

Description

@bengl

Version

v20.6.0 (and all higher versions on even release lines)

Platform

Darwin m1-poutine 24.6.0 Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:29 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6000 arm64 arm Darwin

Subsystem

loaders

What steps will reproduce the bug?

The exact scenario involves two async loaders:

  • The first sets the .source property, as indicated by the docs. It can do anything else, but this is required to reproduce.
  • The second imports a CommonJS file at some point. This needs to be done via an import, and not via createRequire. This is a realistic scenario, because import-in-the-middle is implemented this way.

A reproduction is available here. On versions of Node.js that don't support Module.register, the CLI flags can be used instead to produce the same effect.

How often does it reproduce? Is there a required condition?

100% of the time, given the steps above.

What is the expected behavior? Why is that the expected behavior?

Both loaders should work correctly and not produce an exception as indicated below.

What do you see instead?

node:internal/process/esm_loader:48
      internalBinding('errors').triggerUncaughtException(
                                ^
Error [ERR_METHOD_NOT_IMPLEMENTED]: The resolveSync() method is not implemented
    at new NodeError (node:internal/errors:405:5)
    at Hooks.resolveSync (node:internal/modules/esm/hooks:353:11)
    at ModuleLoader.resolveSync (node:internal/modules/esm/loader:355:35)
    at ModuleLoader.getModuleJobSync (node:internal/modules/esm/loader:225:32)
    at require (node:internal/modules/esm/translators:191:36)
    at Object.<anonymous> (/Users/bengl/broken-loaders/hook2.js:1:1)
    at loadCJSModule (node:internal/modules/esm/translators:207:3)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:233:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:308:24) {
  code: 'ERR_METHOD_NOT_IMPLEMENTED'
}

Node.js v20.6.0

Additional information

We've worked around this in import-in-the-middle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    loadersIssues and PRs related to ES module loaders

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions