Skip to content

Early exit when using dd-trace/loader-hook.mjs and cyclic dependencies #3595

@pwwolf

Description

@pwwolf

Expected behaviour
Node is able to run ES modules with cyclic dependencies without issue. I would expect the same when using the the loader-hook.

Actual behaviour
When specifying --loader dd-trace/loader-hook.mjs, the node process exits early with an exit code 13

Steps to reproduce
Here are a couple modules with a circular dependency, i.e. a imports from b and b imports from a.

Running node a.mjs works as expected, producing output testB\ntestA and exiting with code 0.
Running node --loader dd-trace/loader-hook.mjs a.mjs prints out the standard Custom ESM Loaders warning but then silently exits with code 13 without executing the functions.

a.mjs

import { testB } from './b.mjs';

export function testA() {
        console.log("testA");
}

testB();

b.mjs

import { testA } from './a.mjs';

export function testB() {
        console.log("testB");
        testA();
}

Environment

  • Operation system: MacOS 12.6
  • Node.js version: v18.17.1
  • Tracer version: dd-trace 4.13.1
  • Agent version: n/a
  • Relevant library versions: n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions