Open devjiwonchoi opened 3 weeks ago
Is this only on v18, or also on 20/22/23?
Only on v18
It’s not exactly a bug, it’s a know limitation on Node.js 18.x because the loader hooks are running on the same thread, it cannot support CJS. That being said, the documentation is clearly wrong, definitely deserves fixing
Is there any reference I can look at to learn the context of the limitation? P.S. I'm willing to contribute to the docs update!
I was misremembering things, the off-thread loaders have landed on 18.19.0. I guess the reason you're seeing that issue is that support for CJS source was simply never backported
I'm aware that v18 will be EOL within a few months, but is there a chance it'd be back-ported to v18?
cc @RedYetiDev
Version
Confirmed: v18.19.0, v18.20.3
Platform
Subsystem
No response
What steps will reproduce the bug?
Repro: https://github.com/devjiwonchoi/repro-nodejs-loader-cjs-source
The Node.js loader hook function
load
can return properties:format
andsource
. When running on Node.js v18 withformat
set tocommonjs
, thesource
property is ignored and does not affect the loaded module.Run with
--import ./register.js
Run with
--loader ./loader.mjs
How often does it reproduce? Is there a required condition?
This issue is present on Node.js v18. Works fine on v20. (v19 doesn't support
module.register
API.)What is the expected behavior? Why is that the expected behavior?
The stdout must be:
What do you see instead?
The source is from the
index.js
, not modified from the loader.Additional information
No response