Skip to content
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

Tell esbuild not to load tsconfig #2440

Closed
duarten opened this issue Aug 4, 2022 · 5 comments
Closed

Tell esbuild not to load tsconfig #2440

duarten opened this issue Aug 4, 2022 · 5 comments
Labels

Comments

@duarten
Copy link

duarten commented Aug 4, 2022

esbuild will happily crawl my filesystem to find a tsconfig.json file, and then use its paths configuration to do file resolution. However, in my scenario (a monorepo built with Bazel), this behavior is too invasive and assumes too much.

I can think of two approaches to fix this behaviour:

  1. limit the filesystem crawling to what's under the current working directory;
  2. allow a way to turn this off via the tsconfig option (e.g., if I explicitly set it to undefined, then don't crawl for a tsconfig).

This is related to, but not quite the same as, #2386.

@evanw
Copy link
Owner

evanw commented Aug 4, 2022

This is what the --tsconfig= setting is for. You can use that to override the default one with one of your choosing: https://esbuild.github.io/api/#tsconfig

@duarten
Copy link
Author

duarten commented Aug 4, 2022

How do I specify that I don't want any tsconfig to be loaded?

I'm just giving esbuild JS sources, but because it loads a tsconfig, esbuild will use what's in paths do to path resolution, and will try to load the corresponding TS sources. (That leaves the pnpm workspace and then it can't find deps for those sources - it's a whole can of worms).

I can get around that by updating the resolution extensions, but even then it's awkward for a few reasons (I'm using esbuild through remix, so I don't really have that kind of control without patching remix, and I could have other valid TS entry points). I also get warnings about the tsconfig which pollute the output.

jwnx added a commit to jwnx/remix that referenced this issue Aug 5, 2022
This patch addresses an issue[1] in which Remix looks for a tsconfig
outside the root directory.

We fix this behavior by looking for a tsconfig where it should be
(in the rootDirectory itself) and passing its absolute path to
`tsconfig-paths`. `tsconfig-paths` will then treat the given path as a
tsconfig file path and won't crawl further. If no tsconfig file is
found by us in our root directory, we simply won't call `tsconfig-paths`
at all. Note that crawling up is `tsconfig-path`s intended behavior,
but not Remix's.

A secondary bug that causes this same issue is due to esbuild[2]. When
no tsconfig is passed to esbuild, it will crawl the filesystem up looking
for any tsconfig available and will load it. When tsconfig is explicitly
set to `undefined`, it does the crawling anyways. Unfortunately,
this is a fix that has to be done in `esbuild`, but a few alternatives
to manage this unwanted behavior for now can be:

1. Create an empty tsconfig in the build directory and pass it to esbuild
   so it doesn't crawl outside rootDir;
2. Show a warning to let the user know why the crawling is happening.

Fixes remix-run#3210

[1] remix-run#3210
[2] evanw/esbuild#2440

Signed-off-by: Juliana Oliveira <juliana@uma.ni>
@evanw
Copy link
Owner

evanw commented Aug 5, 2022

It's used like this:

echo "{}" > empty-tsconfig.json
esbuild --bundle --tsconfig=empty-tsconfig.json

@duarten
Copy link
Author

duarten commented Aug 5, 2022

It doesn't seem ideal to provide configuration through the file system. Explicitly setting tsconfig to undefined would be better. I think if a raw tsconfig could be provided to build it would also be better.

All this said, it still seems like undesirable behavior that esbuild will crawl above the working directory.

@evanw
Copy link
Owner

evanw commented Jun 5, 2023

An upcoming change will allow you to pass --tsconfig-raw={} to esbuild to further simplify passing esbuild a custom tsconfig.json file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants