tsx
tsx copied to clipboard
Can't use --inspect and watch at the same time
Bug description
What did you do? (Provide reproduction code in next section)
Ran tsx --inspect watch src/index.ts
What did you expect to happen?
Code the execute successfully, in watch mode, with the --inspect flag being passed to node
What happened instead?
tsx --inspect watch src/index.ts Debugger listening on ws://127.0.0.1:9229/de18515f-4447-4d8a-8d1d-4270a2e9387c For help, see: https://nodejs.org/en/docs/inspector Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/home/shahmirn/dev/logistics-platform/packages/workers/watch' imported from /home/shahmirn/dev/logistics-platform/packages/workers/
Reproduction
cd /tmp
touch index.ts
tsx --inspect watch index.ts
Blows up
tsx watch index.ts and tsx --inspect index.ts both work fine
Environment
System:
OS: Linux 5.10 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
Memory: 4.63 GB / 7.68 GB
Container: Yes
Shell: 5.8 - /home/linuxbrew/.linuxbrew/bin/zsh
Binaries:
Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
Yarn: 1.22.18 - ~/.nvm/versions/node/v16.15.1/bin/yarn
npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
Can you contribute a fix?
- [ ] I’m interested in opening a pull request for this issue.
@shahmirn try flipping the order and putting watch first:
tsx watch --inspect src/index.ts
I got the same ERR_MODULE_NOT_FOUND for ...watch, but flipping the order fixed it.
Fwiw I was expecting a -w or --watch flag instead of just tsx watch; maybe it's too late to change, but it might make the behavior more robust to make watch a flag instead of a command?
Fwiw I really love how this works; I've been stuck on a janky nodemon+swc setup, which constantly disconnects the debugger, but then the port is still in use/locked on restart; with tsx watch --inspect, it "just works", very very nice; thank you @privatenumber !
If tsx watch --inspect src/index.ts does not work for you, try running tsx watch --inspect src/index.ts asd
Watch seems to be failing with one node arg, I guess because arg parser considers file to be --inspect arg value
I was able to get this working using tsx watch -- --inspect src/index.ts
Yes, the --inspect flag needs to be passed in after watch. Otherwise, the watch will be treated as an argument to tsx (as if it's the file path to load).
I'll look into handling --inspect <file path>. As @Dimava speculated, tsx thinks it's an argument to --inspect.
You can now do tsx watch --inspect src/index.ts