Open sou-long opened 8 months ago
Duplicates https://github.com/privatenumber/tsx/issues/265 I think
Please fix your reproduction to:
Done. A nested dir doesn't work with stackblitz due to path
issues, but I modified .stackblitzrc
so it takes the described steps and reproduces the issue immediately.
Workaround seems to be setting the TSX_TSCONFIG_PATH env manually before running tsx e.g.
export TSX_TSCONFIG_PATH=./tsconfig.json && tsx index.ts
Acknowledgements
Minimal reproduction URL
https://stackblitz.com/edit/node-hpyz3n
Version
4.7.0
Node.js version
18.18.2
Package manager
yarn
Operating system
Windows
Problem & Expected behavior
What happened?
I added a custom path into tsconfig.json:
"paths": {"@/*": ["./*"]}
. Then if I runtsx index.ts
in a project directory, all ok. If I run it from other directory, as the linked stackblitz already does (see.stackblitzrc
):then tsx cannot resolve modules referred to by "@/", e.g.
import "@/other.js"
.This prevents using tsx as a loader for cli tools of projects that use tsconfig paths, as in:
This behavior doesn't seem to depend on path template names (
@
,@src
, without@
, etc).What did you expect instead?
For tsx to resolve tsconfig paths based on a resolved project root, e.g.
tsconfig.json/compilerOptions/{rootDir,baseUrl}
. Or maybe based on tsconfig.json's location.So, basically, if regular imports work relative to the importing source file, tsconfig-paths imports, being baseUrl-relative in normal circumstances, should work relative to where tsconfig.json thinks the root is. I believe there's no reason to resolve modules outside of a project root.
Do you have an error stack trace?
Do you have documentation links? Do you have screenshots?
Nope.
Contributions