-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Describe the bug
When running a code hook with Node.js v20 or v22 and ts-node installed globally, the following error occurs:
Error: Cannot find module 'ts-node/register'
Require stack:
- internal/preload
at Function._resolveFilename (node:internal/modules/cjs/loader:1401:15)
...
Node.js v22.15.0 (also happens on v20.12.2)
To Reproduce
Steps to reproduce the behavior:
- Install
ts-nodeglobally:
npm install -g ts-node - Run a hook with:
node -r ts-node/register --no-warnings "/path/to/hooks.user.ts" __run_hook Stop - Observe the error above.
Expected behavior
The hook should run, and ts-node/register should be found as it was in older Node.js versions or when installed locally.
Additional context
- This is not just a Node.js 22+ issue; even with Node.js 20, global modules are not resolved for the
-rflag unless you are in a directory with a local install. - The workaround is to use the absolute path to the global
ts-node/register/index.js, but this is not ergonomic. - Installing
ts-nodelocally in the working directory also works, but is not always desirable.
Environment
- Node.js: v22.15.0 and v20.12.2
- ts-node: 10.9.2 (globally installed)
- OS: macOS
Possible solutions
- Document this Node.js behavior and recommend using the absolute path or local install.
- Consider supporting a config option for specifying the preload path.
Metadata
Metadata
Assignees
Labels
No labels