tsx: `watch` mode in `node.js 20` doesn't watch changes in non-entry files
Bug description
watch mode works on node.js lts/hydrogen v18, but doesn’t on 20+.
Reproduction
- Create 2 files
// file-1.ts - this is your entrypoint
import { example } from './file-2';
console.log(example);
// file-2.ts
export const example = 'Hello World!';
- Run
tsx watch file-1.ts - Modify value in
file-2.ts - Observe there’s
no rerunbytsx
Environment
System:
OS: MacOS (currently latest 13.3)
CPU: m1 pro
Shell: zsh
Binaries:
Node: 20.1.0
npmPackages:
tsx: `3.12.7` (current latest)
Can you work on a fix?
- I’m interested in opening a pull request to address this issue.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 13
- Comments: 15 (4 by maintainers)
Found a temporary solution by using tsx as a loader instead:
Wrote a fix https://github.com/esbuild-kit/esm-loader/pull/64 based on @fspoettel research. Working well for me, but can somebody test it in him configurations also too?
@privatenumber, waiting for review.
Wow thank you so much for the insightful investigation @fspoettel I think we can work on a fix now
I don’t think this is caused by chokidar, but a change to IPC that affects
@esbuild-kit/esm-loader.It appears as if we don’t receive dependency messages from the
esm-loaderanymore. I patched in the following debug logs:https://github.com/esbuild-kit/tsx/blob/9acf1c0eadcc6b7275b91a285acb180171b30d78/src/watch/index.ts#L86
https://github.com/esbuild-kit/esm-loader/blob/332a0a0220dbb80de806ebb3a15ec7c3ce893bee/src/loaders.ts#L214
https://github.com/esbuild-kit/cjs-loader/blob/3442035bd4d1251538141ecd3e80de1add41024a/src/index.ts#L55
This gives the following outputs (on macOS):
Node 18.17.0
Node 20.5.0
In this case, no
esmmodule is ever received asprocess.sendis not defined when the loader tries to send dependencies over IPC.I looked for causes and found this change to the loader API that might be related.
In a github issue that discusses a seemingly similar case, it was suggested that
globalPreloadcould be a workaround.Hope this is helpful!