https://github.com/devjiwonchoi/repro-nodejs-loader-cjs-source
https://github.com/devjiwonchoi/repro-nodejs-loader-cjs-source
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/devjiwonchoi/repro-nodejs-loader-cjs-source
- Owner: devjiwonchoi
- Created: 2024-11-01T10:25:47.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-01T10:55:14.000Z (over 1 year ago)
- Last Synced: 2025-03-25T02:12:22.990Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://github.com/nodejs/node/issues/55630
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
## Issue
> [!NOTE]
> This issue is present on Node.js v18. Works fine on v20. (v19 doesn't support `module.register` API.)
The Node.js loader hook function `load` can return properties: `format` and `source`. When running on Node.js v18 with `format` set to `commonjs`, the `source` property is ignored and has no effect on the loaded module.
### Reproduction
#### Run with `--import ./register.js`
```
node --import ./register.js ./index.js
```
#### Run with `--loader ./loader.mjs`
```
node --loader ./loader.mjs ./index.js
```
### Expected
When format within the `loader.mjs` file is `module`, the stdout should be:
```
{ format: 'module' }
hello from loader.mjs
```
as the "modified" `source` property is provided from the loader.
However, when change the format to `commonjs`, the stdout is:
```
{ format: 'commonjs' }
hello from index.js
```
which is the original `source` from `index.js`.