I wrote a command line application in TypeScript which calls
ts-node through shebang.
It worked fine in both macOS and Linux.
But when I tried to run it in Windows/pwsh, an error occurred.
ts-node package globally to reassure that it is correctly installed:
npm install -g ts-node typescript
However, the error still exits.
ts-node is correctly installed, I can even call it from command line:
Then I tried find where the
ts-node.exe is installed, it surprised me that there is never a
ts-node.exe. No wonder why
pwsh couldn’t find
ts-node globally by running
npm install -g ts-node will only create the following files in npm’s exec directory:
I opened my command line application’s npm executable script to see what went wrong, found that the generated pwsh script is regardlessly calling the ENV declared in shebang through an executable file with a
.exe suffix, and this is obviously wrong!
You can’t call an executable that does
So, I created an alias that maps
ts-node.ps1 which is the right executable to
ts-node.exe to fool my app’s executable script that’s generated by npm.:
# Set an alias in user's PowerShell Profile to enable it globally