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-node globally:
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
-r flag 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-node locally 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.
Describe the bug
When running a code hook with Node.js v20 or v22 and
ts-nodeinstalled globally, the following error occurs:To Reproduce
Steps to reproduce the behavior:
ts-nodeglobally:npm install -g ts-nodeExpected behavior
The hook should run, and
ts-node/registershould be found as it was in older Node.js versions or when installed locally.Additional context
-rflag unless you are in a directory with a local install.ts-node/register/index.js, but this is not ergonomic.ts-nodelocally in the working directory also works, but is not always desirable.Environment
Possible solutions