aleclarson / vite-tsconfig-paths

Support for TypeScript's path mapping in Vite
MIT License
1.23k stars 44 forks source link

Vite fails to resolve files when vite-tsconfig-paths is used alongside vite-plugin-svgr, but only on Windows #143

Open bladeSk opened 1 week ago

bladeSk commented 1 week ago

I've run into a very weird issue with vite-tsconfig-paths, my project suddenly stopped working without me changing anything in it.

After a few hours of debugging, I managed to narrow down the issue and reproduce it in a new Vite+React+TS project. The issue is caused by vite-plugin-svgr, but only on Windows 10 with the latest updates (I suspect it's KB5039211).

The project works perfectly fine on StackBlitz - https://stackblitz.com/edit/vitejs-vite-vmbggc?file=src%2FTest%2FTest.tsx,src%2FApp.tsx,tsconfig.app.json,vite.config.ts&terminal=dev, it works on my outdated Win11 VM, but not on the latest Win10. The issue happens regardless of NodeJS version.

When svgr(...) is commented out in plugins, it starts working again.

I don't know where to even start debugging this. Here's the output of SET DEBUG=vite-tsconfig-paths && npm run dev:

> vite-react-typescript-starter@0.0.0 dev
> vite

  vite-tsconfig-paths options.root   == undefined +0ms
  vite-tsconfig-paths project root   == d:/Code/JS/vitetest +2ms
  vite-tsconfig-paths workspace root == d:/Code/JS/vitetest +1ms
  vite-tsconfig-paths projects: [ 'd:\\Code\\JS\\vitetest\\tsconfig.json' ] +14ms
  vite-tsconfig-paths config loaded: {
  configPath: 'd:/Code/JS/vitetest/tsconfig.app.json',
  config: {
    compilerOptions: {
      composite: true,
      tsBuildInfoFile: './node_modules/.tmp/tsconfig.app.tsbuildinfo',
      target: 'ES2020',
      useDefineForClassFields: true,
      lib: [ 'ES2020', 'DOM', 'DOM.Iterable' ],
      module: 'ESNext',
      skipLibCheck: true,
      moduleResolution: 'bundler',
      allowImportingTsExtensions: true,
      resolveJsonModule: true,
      isolatedModules: true,
      moduleDetection: 'force',
      noEmit: true,
      jsx: 'react-jsx',
      strict: true,
      noUnusedLocals: true,
      noUnusedParameters: true,
      noFallthroughCasesInSwitch: true,
      baseUrl: 'd:/Code/JS/vitetest/src'
    },
    include: [ 'src' ]
  }
} +7ms
  vite-tsconfig-paths compiled globs: {
  includers: [ /^\.\/src\/((?:[^/]*(?:\/|$))*)$/ ],
  excluders: [
    /^\.\/((?:[^/]*(?:\/|$))*)node_modules\/((?:[^/]*(?:\/|$))*)$/,
    /^\.\/((?:[^/]*(?:\/|$))*)bower_components\/((?:[^/]*(?:\/|$))*)$/,
    /^\.\/((?:[^/]*(?:\/|$))*)jspm_packages\/((?:[^/]*(?:\/|$))*)$/
  ]
} +21ms
  vite-tsconfig-paths config loaded: {
  configPath: 'd:/Code/JS/vitetest/tsconfig.node.json',
  config: {
    compilerOptions: {
      composite: true,
      tsBuildInfoFile: './node_modules/.tmp/tsconfig.node.tsbuildinfo',
      skipLibCheck: true,
      module: 'ESNext',
      moduleResolution: 'bundler',
      allowSyntheticDefaultImports: true,
      strict: true,
      noEmit: true
    },
    include: [ 'vite.config.ts' ]
  }
} +5ms
  vite-tsconfig-paths [!] missing baseUrl and paths: "d:/Code/JS/vitetest/tsconfig.node.json" +9ms
  vite-tsconfig-paths config loaded: {
  configPath: 'd:/Code/JS/vitetest/tsconfig.json',
  config: {
    files: [],
    references: [
      { path: './tsconfig.app.json' },
      { path: './tsconfig.node.json' }
    ]
  }
} +1ms
  vite-tsconfig-paths [!] skipping "d:/Code/JS/vitetest/tsconfig.json" as no files can be matched since "files" is empty and "include" is missing or empty +6ms

  VITE v5.3.2  ready in 429 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help
Error: The following dependencies are imported but could not be resolved:

  Test/Test (imported by D:/Code/JS/vitetest/src/App.tsx)

Are they installed?
    at file:///d:/Code/JS/vitetest/node_modules/vite/dist/node/chunks/dep-C1-ZB6nQ.js:51147:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async file:///d:/Code/JS/vitetest/node_modules/vite/dist/node/chunks/dep-C1-ZB6nQ.js:50652:26
bladeSk commented 1 week ago

Not sure if this is really an issue with vite-plugin-svgr, my actual project doesn't work even when the plugin is removed. 🤔 Unfortunately, I can't narrow down when it stops working.