Ts-node: Use shebang if installing locally?

Created on 13 Jul 2018  Â·  6Comments  Â·  Source: TypeStrong/ts-node

I just discovered that shebang support wasn't working on my build machine because I have installed ts-node locally, and then was running the .ts file with a shebang like: #!/usr/bin/env ts-node as referenced in #73

That works if you have ts-node installed globally, or if you have it installed locally, and have ./node_modules/.bin on your path, but if you don't have node_modules/.bin on your path, it doesn't appear to work, and this makes sense. My current workaround would be to rely upon npx and use the shebang #!npx ts-node, since npx is installed with ts-node. I just wanted to make sure I'm not missing anything since #73 claims that the /usr/bin/env shebang should "just work".

question

Most helpful comment

@samuela Pointing to the env file worked for me

#!/usr/bin/env npx ts-node

This is not working for me:

/usr/bin/env: ‘npx ts-node’: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines

I've fixed it in this way:

#!/usr/bin/env -S npx ts-node

All 6 comments

You’re right, it definitely needs to be global and in your path (just like any other globally installed node.js module). I personally wouldn’t recommend it as a feature, but that issue asks if it’s possible and it certainly is - using npx or just running the script directly from ts-node would make it more resilient, possible to use local versions from package.json and better support cross platform.

I also really need this!

Using #!npx ts-node doesn't work for me:

-bash: ./yarn-run-all.ts: npx: bad interpreter: No such file or directory

@samuela Pointing to the env file worked for me

#!/usr/bin/env npx ts-node

@samuela Pointing to the env file worked for me

#!/usr/bin/env npx ts-node

This is not working for me:

/usr/bin/env: ‘npx ts-node’: No such file or directory
/usr/bin/env: use -[v]S to pass options in shebang lines

I've fixed it in this way:

#!/usr/bin/env -S npx ts-node

Sadly npx ts-node didn't work on a colleage's MacOs out of the box
so I compiled the typescript files to js but they doesn't detect the local dependencies with #!/usr/bin/env node

I hope that #!/usr/bin/env npx works on Mac as it does on my Linux :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JoseLion picture JoseLion  Â·  3Comments

sodiumjoe picture sodiumjoe  Â·  4Comments

remojansen picture remojansen  Â·  4Comments

motss picture motss  Â·  4Comments

aj-r picture aj-r  Â·  3Comments