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 breaks in Node 16.17.0 when using node internals (Changes backported from Node 18) #20

Closed lfre closed 2 years ago

lfre commented 2 years ago

Expected Behavior

The loader does not throw when using node internals in Node 16.17.0.

Actual Behavior

Any usage of node internals, e.g.: fs, will cause the program to throw in Node 16.17.0 (LTS as of this writing).

Loader changes from Node 18 were backported to Node 16.17.0 https://github.com/nodejs/node/releases/tag/v16.17.0

Steps to Reproduce the Problem

  1. Install/upgrade to Node 16.17.0.
  2. Add an import to a node internal. E.g: import * as fs from 'fs'; in an ESM project.
  3. Run node with --loader point to the hook.mjs file.

Specifications

Node 18 is expected to be LTS by October 2022, which will make the NODE_MAJOR check work again, but otherwise, the check should be updated to account 16.17+ as well.

bengl commented 2 years ago

This is fixed in 1.3.1, so I'll close this. Please feel free to comment if that doesn't work for you.