Closed leumasme closed 1 year ago
I can't reproduce this I'm afraid - I've just tested tsc in an intercepted terminal and it works fine.
This might be related to some specifics of how your project config is setup - can you share that so I can test this directly?
The way this works is that when node
is run on your system, it actually runs this wrapper .bat file which runs the 'real' node with an extra -r "%WRAPPER_FOLDER%\..\js\prepend-node.js"
argument. That WRAPPER_FOLDER
variable is set within that file, relative to the path to that wrapper bat file, so I have no idea how it could become "S:\Dev\my-project\". Anything unusual about your setup at all, or anything else you can think of that might cause this?
Or maybe this is related to powershell... What happens if you do the same from a cmd.exe
terminal?
Running npm -v
and tsc -v
without npx
seems to work fine.
So it seems that this is not related to typescript at all but instead... npx?
Below is a terminal log, starting from a fresh cmd session.
npm run <script>
automatically runs the commands of the package.json
script in an npx
environment, so these will error even if called without npx
.
You can also run npx
without arguments to get into a (cmd) npx environment, where commands like npm -v
will again fail.
It seems likely that the npx
environment doesn't carry over the WRAPPER_FOLDER
variable set in the bat script, leading to the path to prepend-node.js
being incorrectly built, but I couldn't reproduce this by just setting a variable and echoing it from within npx
.
but I couldn't reproduce this by just setting a variable and echoing it from within
npx
To amend that:
Adding an echo Within node.bat, the wrapper is %WRAPPER_FOLDER% / %~dp0
to node.bat
always yields the current path of the terminal, instead of the location of the bat file, if ran through npx
.
If the bat file is manually ran by just pasting its abolute path into the terminal, it correctly prints the location of the bat file. Huh!?
It seems that Powershell runs batch scripts happily, but runs them in subtly different ways to cmd.exe, and that clearly causes some problems.
I've found a way to refactor these scripts to avoid needing to query the script path entirely: https://github.com/httptoolkit/httptoolkit-server/commit/00ee967317211e0094f6b5ce18e74bc53b4aef86. This seems to work in my testing, and neatly sidesteps the issue. Can you test that out, and check it works for you?
Yes, copying over the bat file from the commit resolves this issue for me. Thanks for your great work!
My steps to cause this error:
npx tsx
in my typescript/nodejs projectThe error:
Some extra info:
npx tsc
to run the typescript compiler causes the error4.8.4