Closed guillenotfound closed 2 years ago
Maybe it's because vite.config.ts
it's a ts file and therefor needs a tsconfig
file in place? But the output looks like esbuild...
Are you sure this plugin has any effect on that error?
Sorry for the delay, here is a repo with the reproduction, readme contains all the information I've found: https://github.com/guillenotfound/preact-tsconfig
Hey aleclarson, sorry I was missing one commit.
Basically what matters is that I'm referencing tsconfig.custom.json
here in order to avoid default tsconfig.json
file:
https://github.com/guillenotfound/preact-tsconfig/blob/main/vite.config.ts#L8
Then, tsconfig.custom.json
points to nodeB
file which does not exist, is just a placeholder in order to debug which tsconfig.*
is getting picked:
https://github.com/guillenotfound/preact-tsconfig/blob/main/tsconfig.custom.json#L22
But when running npm run dev
I'd be expecting nodeB
missing, but instead nodeA
(the one referenced in tsconfig.json
) is the one missing. So it seems like for some reason it's using tsconfig.json
rather than tsconfig.custom.json
which is the one I'm referencing in the config.
Further checks stats that if I remove default tsconfig file, this plugin works as expected but not if there's default tsconfig.json
file in place.
Let me know if you follow me know, otherwise I'll record a quick video to do the showcase.
This plugin only crawls the filesystem if the projects
option is undefined. See here:
https://github.com/aleclarson/vite-tsconfig-paths/blob/7dd87731d6753aad08fe8e948eb5783942e477ec/src/index.ts#L204-L211
The logs in your OP seem to suggest the tsconfig.vite.json
file is being loaded:
vite-tsconfig-paths [!] missing baseUrl and paths: "/project/tsconfig.vite.json"
I think you need to tell Esbuild which tsconfig to use:
// vite.config.ts
export default defineConfig({
esbuild: {
tsconfig: 'tsconfig.vite.json',
},
})
Didn't know about that config, thanks! 🙏
BTW project option is set and it still uses tsconfig.json
for some reason, were you able to reproduce it?
But when running npm run dev I'd be expecting nodeB missing, but instead nodeA (the one referenced in tsconfig.json) is the one missing. So it seems like for some reason it's using tsconfig.json rather than tsconfig.custom.json which is the one I'm referencing in the config.
When I run the reproduction with DEBUG="vite-tsconfig-paths" vite dev
, I get these logs:
vite-tsconfig-paths options: {
projects: [ '/workspaces/preact-tsconfig/tsconfig.custom.json' ],
extensions: [ '.ts', '.tsx', '.js', '.jsx', '.mjs' ]
} +0ms
vite-tsconfig-paths [!] missing baseUrl and paths: "/workspaces/preact-tsconfig/tsconfig.custom.json" +3ms
…which indicate only tsconfig.custom.json
is being loaded.
Otherwise, you'd see this debug log: https://github.com/aleclarson/vite-tsconfig-paths/blob/7dd87731d6753aad08fe8e948eb5783942e477ec/src/index.ts#L67
As you can see, when
tsconfig.json
exists it will pick it up, I know it might not be the plugin but vite itself, is there any way to bypass this behaviour?