-
-
Notifications
You must be signed in to change notification settings - Fork 533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use shebang if installing locally? #639
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 |
I also really need this! |
Using
|
@samuela Pointing to the #!/usr/bin/env npx ts-node |
This is not working for me:
I've fixed it in this way:
|
Sadly I hope that |
I have been searching for a way to use a shebang with locally installed After messing around a bit, I came up with an ugly way to do this but it works and is a one-liner:
So, if you have a script called
You can use it like this:
Benefits:
|
|
The way it actually works on all platforms is to use plain node/JS with a standard shebang for node (this executable is always globally available), run {
scripts: {
"start:ts": "ts-node yourCommand.ts"
}
} Point is, that npm will take care for the lookup then internally with node-resolve algo and this also works on any platform and of course also with npx -- which gives you headaches because npx would install in different directory stuctures because of caching |
FYI ts-node does Globally-installed ts-node is smart enough to use locally-installed versions of typescript and @types/node, so generally you can install the most recent version of ts-node globally and then use Here is an example of a project configured to be installed and run via
You can avoid the overhead of Even better, you can avoid the overhead of child_process by using our API.
https://typestrong.org/ts-node/api/index.html#register |
This allows `ts-node` to be used to run TypeScript files without having to compile them with `tsc` first. It also adds the necessary configs, including `tsconfig-paths` for `paths` import-alias resolution. Unfortunately, this means we have to remove the `--experimental-module-resolution=node` since `ts-node` uses its own loader and thus form of resolving modules. See: Setup * https://medium.com/@jimcraft123hd/setting-up-path-alias-in-typescript-and-tsc-build-without-error-9f1dbc0bccd2 Issues with `ts-node`, ESM, and aliases * TypeStrong/ts-node#1007 - TypeStrong/ts-node#476 - dividab/tsconfig-paths#122 (comment) - TypeStrong/ts-node#1450 (comment) * TypeStrong/ts-node#1414 * TypeStrong/ts-node#995 - TypeStrong/ts-node#639 Node issues with ESM * https://nodejs.org/api/packages.html#determining-module-system * nodejs/node#37468
This allows `ts-node` to be used to run TypeScript files without having to compile them with `tsc` first. It also adds the necessary configs, including `tsconfig-paths` for `paths` import-alias resolution. Unfortunately, this means we have to remove the `--experimental-module-resolution=node` since `ts-node` uses its own loader and thus form of resolving modules. See: Setup * https://medium.com/@jimcraft123hd/setting-up-path-alias-in-typescript-and-tsc-build-without-error-9f1dbc0bccd2 Issues with `ts-node`, ESM, and aliases * TypeStrong/ts-node#1007 - TypeStrong/ts-node#476 - dividab/tsconfig-paths#122 (comment) - TypeStrong/ts-node#1450 (comment) * TypeStrong/ts-node#1414 * TypeStrong/ts-node#995 - TypeStrong/ts-node#639 Node issues with ESM * https://nodejs.org/api/packages.html#determining-module-system * nodejs/node#37468
This allows `ts-node` to be used to run TypeScript files without having to compile them with `tsc` first. It also adds the necessary configs, including `tsconfig-paths` for `paths` import-alias resolution. Unfortunately, this means we have to remove the `--experimental-module-resolution=node` since `ts-node` uses its own loader and thus form of resolving modules. See: Setup * https://medium.com/@jimcraft123hd/setting-up-path-alias-in-typescript-and-tsc-build-without-error-9f1dbc0bccd2 Issues with `ts-node`, ESM, and aliases * TypeStrong/ts-node#1007 - TypeStrong/ts-node#476 - dividab/tsconfig-paths#122 (comment) - TypeStrong/ts-node#1450 (comment) * TypeStrong/ts-node#1414 * TypeStrong/ts-node#995 - TypeStrong/ts-node#639 Node issues with ESM * https://nodejs.org/api/packages.html#determining-module-system * nodejs/node#37468
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 #73That 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".The text was updated successfully, but these errors were encountered: