Open
Description
Expected Behavior
Using a myloader.mjs
file like this
import * as module from 'module'
module.register('import-in-the-middle/hook.mjs', import.meta.url)
and using NODE_OPTIONS='--import ./myloader.mjs' $my_command
does not crash.
Actual Behavior
Running
NODE_OPTIONS='--import ./myloader.mjs' npm run test:vitest
results in
(node:81156) Error: 'import-in-the-middle' failed to wrap 'file:///Users/juan.fernandezdealba/Desktop/dev/starter-kit-juan-fork/node_modules/@prisma/client/default.js'
Steps to Reproduce the Problem
- Clone my
starter-kit
fork:
git clone [email protected]:juan-fernandez/starter-kit.git
cd starter-kit
- Install dependencies
npm i
- Run vitest test command with
--import
flag:
NODE_OPTIONS='--import ./myloader.mjs' npm run test:vitest
See this error:
(node:81156) Error: 'import-in-the-middle' failed to wrap 'file:///Users/juan.fernandezdealba/Desktop/dev/starter-kit-juan-fork/node_modules/@prisma/client/default.js'
Specifications
Running npx envinfo
System:
OS: macOS 14.7
CPU: (10) arm64 Apple M1 Max
Binaries:
Node: 20.17.0 - ~/.volta/tools/image/node/20.17.0/bin/node
npm: 10.8.2 - ~/.volta/tools/image/node/20.17.0/bin/npm
Investigation
If you look at node_modules/@prisma/client/default.js
the file looks like this:
module.exports = {
...require('.prisma/client/default'),
}
Funnily enough, if you change the file contents to this:
const res = require('.prisma/client/default')
module.exports = {
...res,
}
the crash does not happen anymore.
Context
Extra repro case
https://github.com/juan-fernandez/iitm-issue-repro is lighter. It does not throw the same exact error but seems to be caused with a very similar setup, so it's likely to be related