Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vite-tsconfig-paths resolves the paths correctly but vite cannot find the files - though they exist

Tags:

vite

I try to use paths from tsconfig in my vite config but it doesn't work. Vite tells me it cannot find the files though it resolves them correctly as I found when using DEBUG=vite-tsconfig-paths to get debug info when running

Then it says e.g

vite-tsconfig-paths resolved: { id: '@common/AssetLoader',
importer: 'C:/Users/tom/data/m3d/frontend/modeller/src/main.ts',
resolvedId: 'C:/Users/tom/data/m3d/frontend/common/src/AssetLoader.ts',
configPath: 'C:/Users/tom/data/m3d/frontend/tsconfig.json' } +9ms

which is perfect and I can also open the Assetloader file with that path

But later in the console it says

Error: The following dependencies are imported but could not be resolved:

@common/AssetLoader (imported by C:/Users/tom/data/m3d/frontend/modeller/src/components/ViewS.vue?id=0)

and the same for other files. So I dont understand whats going on since it seesm to resolve the path correctly but then cannot find the existing files

My vite config is like this:

import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig({. 
   plugins: [
      vue(),
      tsconfigPaths({ root: './' })// also tried without parameter
   ]
})

Any ideas someone? Cheers Tom

like image 617
TomFree Avatar asked Oct 20 '25 00:10

TomFree


1 Answers

After running into this myself, I found a config option "loose" that seems to have fixed it, though I don't honestly know why.

plugins: [
    viteTsConfigPaths({
      loose: true,
      root: '../../',
    }),
  ],
like image 186
Nick Wiltshire Avatar answered Oct 22 '25 06:10

Nick Wiltshire



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!