esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

Tell esbuild not to load tsconfig

Open duarten opened this issue 2 years ago • 4 comments

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.

duarten avatar Aug 04 '22 18:08 duarten

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

evanw avatar Aug 04 '22 22:08 evanw

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.

duarten avatar Aug 04 '22 22:08 duarten

It's used like this:

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

evanw avatar Aug 05 '22 21:08 evanw

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.

duarten avatar Aug 05 '22 21:08 duarten

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

evanw avatar Jun 05 '23 06:06 evanw