Skip to content

Loader fails when circular dependencies exist within an application #32

@bizob2828

Description

@bizob2828

Expected Behavior

When running an application that has circular deps with import-in-the-middle, it should handle this accordingly.

Actual Behavior

It silently fails in pre Node 20, and in Node 20 errors with

file:///Users/revans/code/cyclic-loader-issue/dep-2.js:5
  dep1()
  ^

ReferenceError: Cannot access 'dep1' before initialization
    at dep2 (file:///Users/revans/code/cyclic-loader-issue/dep-2.js:5:3)
    at file:///Users/revans/code/cyclic-loader-issue/dep-1.js:7:1
    at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:308:24)
    at async loadESM (node:internal/process/esm_loader:42:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

Steps to Reproduce the Problem

  1. git clone https://github.com/bizob2828/cyclic-loader-issue
  2. npm i && npm run start

Specifications

  • Version: Node 16,18,20.
  • Platform: All
  • Subsystem: All

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions