nodejs / import-in-the-middle

Like `require-in-the-middle`, but for ESM import
https://www.npmjs.com/package/import-in-the-middle
Apache License 2.0
60 stars 22 forks source link

Loader fails when circular dependencies exist within an application #32

Open bizob2828 opened 11 months ago

bizob2828 commented 11 months ago

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

mjsalinger commented 7 months ago

Hi - is there any chance on solving this?

timfish commented 2 months ago

Confirmed this is still an issue with v1.8.1

jsumners-nr commented 2 months ago

Hi - is there any chance on solving this?

Pull requests are welcome.