tsx
tsx copied to clipboard
support multiple `tsconfig`s
Bug description
My project has separate tsconfig.json files for source and test files. When setting up the paths compiler option, my IntelliSense correctly provides type information for imports, but tsx fails with the ERR_MODULE_NOT_FOUND error.
Reproduction
https://github.com/tommy-mitchell/tsx-repro
// test/test.ts
import assert from "node:assert";
import { foo } from "~/index.ts"; // Errors here
import type { Foo } from "~/types.ts";
assert.strictEqual(foo() as Foo, "bar");
Environment
System:
OS: macOS 13.3.1
CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Memory: 107.30 MB / 8.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.16.1 - ~/.nvm/versions/node/v18.16.1/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v18.16.1/bin/yarn
npm: 9.5.1 - ~/.nvm/versions/node/v18.16.1/bin/npm
pnpm: 8.6.7 - ~/.nvm/versions/node/v18.16.1/bin/pnpm
npmPackages:
tsx: ^3.12.7 => 3.12.7
Can you work on a fix?
- [ ] I’m interested in opening a pull request to address this issue.
Sorry for posting in the other issue, thought it'd be relevant because they were both about the paths option :) my bad.
Maybe this has to do with how @esbuild-kit/esm-loader loads tsconfig.json? At a glance, it looks like it's only loaded once per project: https://github.com/esbuild-kit/esm-loader/blob/13ce0ca4978635618bc65bc94f3c8f92131d45c1/src/utils.ts#L13-L23
@privatenumber,
Could you explain why, when I place a custom configuration file in the directory with the executable script, it is not being picked up? In my project, there is a global tsconfig.json file where the target is set to es5, but my script requires es2017. I added a custom configuration file in the script's directory and specified its path in tsconfig.json. It feels like the tsx configuration does not recognize this file and continues to refer to the global one.
Why not simply add the ability to override options from the global configuration, for example, using something like --target=es2017?
Looks not good:
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"target": "es2017",
"paths": {
"@/*": [
"../../../src/*"
]
}
}
}
@tommy-mitchell In the case within the reproduction tsx-repro pointing directly to the tsconfig assists e.g.
"start": "tsx --tsconfig ./test/tsconfig.json test/test.ts"
May give some milage for similar path resolution issue.