tsx
tsx copied to clipboard
import in referenced typescript project fail to load
Bug description
When working with composite projects, our tests failed because it seems that tsx
is not taking the reference project's baseUrl or path into consideration.
Reproduction
Test project:
https://github.com/steabert/esbuild-kit-tsx-composite.git
To reproduce the issue:
yarn install
yarn fail
Running yarn bundle
and yarn types
shows the result with e.g. esbuild
or tsc
.
It seems this does not work with ts-node
either, but I don't know how they handle composite typescript projects.
Environment
npx envinfo --system --npmPackages tsx --binaries
System:
OS: Linux 5.4 Ubuntu 20.04.4 LTS (Focal Fossa)
CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
Memory: 23.58 GB / 31.21 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 16.14.2 - ~/.node/bin/node
Yarn: 3.2.3 - ~/.npm-global/bin/yarn
npm: 8.5.0 - ~/.node/bin/npm
npmPackages:
tsx: 3.9.0 => 3.9.0
Can you contribute a fix?
- [x] I’m interested in opening a pull request for this issue.
Also, looks similar to #76 maybe?
Yes, this is the same problem as reported in #76. unlike esbuild, tsx ignores tsconfig.json in referenced packages.
How does esbuild handle custom tsconfig.json
paths via the tsconfig
CLI flag for multiple projects?
e.g. If project A uses tsconfig.a.json
and its dependency project B uses tsconfig.b.json
, how is it configured?
I don't need to specify any configuration, esbuild seems to find the correct tsconfig associated with an imported module. However, I think it only does that when bundling. I forgot where I read that, I think it was in the comments on one of the esbuild issues, I'll try to find it again.
Edit: here was the comment that I found saying what the behaviour is, but nothing in detail how it's resolved.
My own (naive?) way would be to walk up the directory tree of an imported file if there is no associated tsconfig, and if a new tsconfig.json
file is found, check its include files and cache it for later use. That way, each included file would have an associated tsconfig file.
My question is more about API design than your specific use-case.
Understanding how esbuild's API handles custom tsconfig.json
paths across multiple projects would help.
The esbuild author replied in my issue, but that seems to be also about how esbuild itself finds tsconfig files. That doesn't seem to be the info you're after, I'm afraid I haven't dealt with the esbuild API at all.
To be fair, you asked him a different question from the one I asked you.
I don't have time for this now, but if you're interested in helping, you can investigate by setting up a project with the structure I described here and trying to make it work with esbuild. Maybe @IlyaSemenov can help.
Based on what Evan said, I'm skeptical if esbuild is also following TS behavior correctly (not that tsx currently is either). For example, does it even allow for custom tsconfig.json
paths? And does it check against tsconfig.json#files/includes/excludes
?
We are also running into this problem. I might be able to help but I'm not sure what you mean by
you can investigate by setting up a project with the structure [...] and trying to make it work with esbuild.
How does esbuild handle custom
tsconfig.json
paths via thetsconfig
CLI flag for multiple projects? e.g. If project A usestsconfig.a.json
and its dependency project B usestsconfig.b.json
, how is it configured?
Like @steabert described, with esbuild it already works because esbuild detects tsconfig.b.json
by itself. Do you want to know whether it still works if we additionally specify tsconfigs manually, even though that's not required?
I'm skeptical that esbuild would successfully build. My understanding is that it only detects tsconfig.json
, and not tsconfig.b.json
.
To prove that this works, please create a repository containing a monorepo with two tsconfigs under custom names and add a build script to demonstrate that esbuild can successfully build it. If you'd like, you can reuse https://github.com/steabert/esbuild-kit-tsx-composite but rename the tsconfig.json
of the dependency and test if it builds.
And if that doesn't build, please find out what configuration esbuild offers to specify a custom tsconfig.json
name.