-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
Allow scripts to be run without a file extension #175
Comments
Sorry I don't understand the request. Can you elaborate on your use-case? |
What I meant was: > cat test.mts
#!/usr/bin/env tsx
console.log('hello');
> ./test.mts
hello
> cp test.mts test
> chmod u+x test
> ./test
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for /Users/engin/code/cliui/test
at __node_internal_captureLargerStackTrace (node:internal/errors:464:5)
at new NodeError (node:internal/errors:371:5)
at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:87:11)
at defaultGetFormat (node:internal/modules/esm/get_format:102:38)
at defaultLoad (node:internal/modules/esm/load:21:14)
at x (file:///Users/engin/.local/share/nvm/v16.14.0/lib/node_modules/tsx/node_modules/@esbuild-kit/esm-loader/dist/index.js:1:2902)
at ESMLoader.load (node:internal/modules/esm/loader:359:26)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:280:58)
at new ModuleJob (node:internal/modules/esm/module_job:66:26)
at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:297:17)
at ESMLoader.getModuleJob (node:internal/modules/esm/loader:261:34)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
at async loadESM (node:internal/process/esm_loader:88:5)
at async handleMainPromise (node:internal/modules/run_main:61:12) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
} |
Sorry, I'm not interested in this enhancement. Explicit extensions are enforced by Node.js as a part of ESM. You can file the request with Node.js or add your own custom Node.js loader though. |
@engina is this actually working? Or is it your proposed solution? I'm getting an error |
It was my proposed solution. It won't work for you. I ended up doing a Makefile and a shell alias. # Makefile
dist/ecm.js: $(shell find apps/ecm/src/ -type f)
esbuild apps/ecm/src/main.ts --platform=node --bundle --minify --outfile=dist/ecm.js alias ecm='make -s dist/ecm.js; node dist/ecm.js This compiles the ts command line utility if source codes are changed. If not , just runs the already compiled version. Even in the "cold boot" where it compiles and runs the tool, it does it faster than tsx.
|
Related: nodejs/node#34049 Hope they find a Node.js solution to this. |
Are we there yet? nodejs/node#34049 (comment) |
I haven't. Missed the part about holding off on back-porting to 20.X. I'll give it a try and report back. |
Sorry, I was a little quick reading the issue description here. My use case is not for scripts. It's for running AVA without transpiling TS to JS first. Works fine in 18, but not in 20 (new LTS). Oh, well, sorry for the interruption. |
Feature request
A command line parameter to tsx to force extension.
Why?
It's slower to type the script name with the extension, especially because
.
character is in an inconvenient place.Or if it's in your path
Alternatives
Enfore extension in the shebang
Additional context
And when you add the script to the PATH it will be just another tool in your work environment.
The text was updated successfully, but these errors were encountered: