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

tsconfig option only allowed for Build, but not for Transform #3171

Closed
ghost opened this issue Jun 16, 2023 · 2 comments
Closed

tsconfig option only allowed for Build, but not for Transform #3171

ghost opened this issue Jun 16, 2023 · 2 comments

Comments

@ghost
Copy link

ghost commented Jun 16, 2023

Currently, the tsconfig option is only allowed for Build: https://esbuild.github.io/api/#tsconfig
However, I'm using vite which only allows esbuild transform (TransformOptions); tsconfig is not usable.

esbuild (through vite) currently defaults to our "IDE-only" tsconfig.json with stricter checks. As a result, we get lots of warnings and errors due to stricter checks than our code can satisfy.
What it should be using instead, is our more lax tsconfig.build.json (which our code does satisfy).

This is also the original problem from #226 which was solved by adding tsconfig to the Build options in 9ac27fa

For that, I'd like to have this in our vite config:

  [...]
  esbuild: {
    tsconfig: './tsconfig.build.json'
  },
  [...]

However, that's not allowed, because esbuild:

  • in vite config is esbuild?: ESBuildOptions | false;..
  • where interface ESBuildOptions extends EsbuildTransformOptions..
  • where import { TransformOptions as EsbuildTransformOptions } from 'esbuild'; which is..

esbuild/lib/shared/types.ts

Lines 255 to 264 in 73ee85a

export interface TransformOptions extends CommonOptions {
/** Documentation: https://esbuild.github.io/api/#sourcefile */
sourcefile?: string
/** Documentation: https://esbuild.github.io/api/#loader */
loader?: Loader
/** Documentation: https://esbuild.github.io/api/#banner */
banner?: string
/** Documentation: https://esbuild.github.io/api/#footer */
footer?: string
}

While commonOptions allows tsconfigRaw, it does not allow tsconfig.


For vite, there's also a discussion about specifying the tsconfig.json, and this is a suggested workaround: vitejs/vite#10531 (comment)
That basically loads tsconfig.json and plugs it into the tsconfigRaw.
I assume that esbuild still loads the actual "tsconfig.json" (which shouldn't be necessary) and then overwrites (or even merges?) the tsconfigRaw, which might lead to unexpected results.

@evanw
Copy link
Owner

evanw commented Jun 16, 2023

The only way to pass tsconfig.json to the transform API is with tsconfigRaw: https://esbuild.github.io/api/#tsconfig-raw. The transform API is intended to be used without a file system, so it doesn’t make sense to pass it a file system path.

If you want esbuild to search the file system when building (for at least both tsconfig.json and package.json), you can use the build API instead.

@ghost ghost changed the title tsconfig option only allowd for Build, but not for Transform tsconfig option only allowed for Build, but not for Transform Jun 16, 2023
@ghost
Copy link
Author

ghost commented Jun 16, 2023

Thanks for the quick response.

I assume it's the responsibility of vite to parse tsconfig into tsconfigRaw then.
As far as I'm concerned this issue is resolved.

I'll keep watching vitejs/vite#10531 then.

Closed.

@ghost ghost closed this as not planned Won't fix, can't repro, duplicate, stale Jun 16, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant