Environment
System:
OS: macOS 15.6.1
CPU: (10) arm64 Apple M1 Max
Memory: 569.75 MB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.18.0
npm: 10.9.3
pnpm: 10.18.0
bun: 1.1.30
Browsers:
Chrome: 140.0.7339.214
Safari: 18.6
Reproduction
https://github.com/Timeless0911/jiti-resolve-path-issue
- Run
pnpm install
- Run
cd libs/b && pnpm run jiti
Describe the bug
const path = require.resolve("is-odd", {
paths: [require.resolve("a")],
});
console.log("path: ", path);
The libs/b/index.ts write a require.resolve with paths option to resolve is-odd.
In Node.js, is-odd can be resolved
> require.resolve("is-odd", { paths: [require.resolve("a")],})
'<PATH>/node_modules/.pnpm/is-odd@3.0.1/node_modules/is-odd/index.js'
But when resolved with JavaScript API of jiti, it throws error Cannot find module 'is-odd'
> node jiti.ts
node:internal/modules/cjs/loader:1365
const err = new Error(message);
^
Error: Cannot find module 'is-odd'
Require stack:
- <PATH>/libs/b/index.ts
at Function._resolveFilename (node:internal/modules/cjs/loader:1365:15)
at Function.resolve (node:internal/modules/helpers:145:19)
Additional context
If we use bin file of jiti, which is jiti index.ts, the error will not be threw since pnpm will generate NODE_PATH in node_modules/.bin/jiti.
I suspect that there is some missing in the paths options passed during the jiti resolve process or jiti should respect paths options user write when using require.resolve.
Environment
System:
OS: macOS 15.6.1
CPU: (10) arm64 Apple M1 Max
Memory: 569.75 MB / 64.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.18.0
npm: 10.9.3
pnpm: 10.18.0
bun: 1.1.30
Browsers:
Chrome: 140.0.7339.214
Safari: 18.6
Reproduction
https://github.com/Timeless0911/jiti-resolve-path-issue
pnpm installcd libs/b && pnpm run jitiDescribe the bug
The
libs/b/index.tswrite arequire.resolvewithpathsoption to resolveis-odd.In Node.js,
is-oddcan be resolvedBut when resolved with JavaScript API of jiti, it throws error
Cannot find module 'is-odd'Additional context
If we use bin file of jiti, which is
jiti index.ts, the error will not be threw since pnpm will generateNODE_PATHinnode_modules/.bin/jiti.I suspect that there is some missing in the paths options passed during the jiti resolve process or jiti should respect
pathsoptions user write when usingrequire.resolve.