Skip to content

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

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

Open
bladeSk opened this issue Jun 27, 2024 · 6 comments
Labels
platform: windows waiting for response The issue author needs to reply

Comments

@bladeSk
Copy link

bladeSk commented Jun 27, 2024

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:

> [email protected] 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
Copy link
Author

bladeSk commented Jun 27, 2024

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.

@aleclarson
Copy link
Owner

I believe this has been fixed in #157. Let me know otherwise.

@bladeSk
Copy link
Author

bladeSk commented Dec 5, 2024

Unfortunately, it's still not working on Windows - here's the project with dependencies updated to the latest versions (vite-tsconfig-paths is at 5.1.3) https://stackblitz.com/edit/vitejs-vite-rypg1h?file=src%2FTest%2FTest.tsx,src%2FApp.tsx,package.json&terminal=dev

I'm getting the same error:

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-A4nAWF7x.js:18523: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-A4nAWF7x.js:51323:28

@aleclarson aleclarson reopened this Dec 5, 2024
@ThiBash
Copy link

ThiBash commented Mar 27, 2025

I'm having a similar problem. Our project uses vite-tsconfig-paths for a runtime import in a .spec file. It works on other people's Mac machines, and in the pipeline, but not on local Windows-based machines.

Error: Failed to load url @alias/someFolder/someFile.json (resolved id: @alias/someFolder/someFile.json). Does the file exist?

@aleclarson
Copy link
Owner

aleclarson commented Apr 16, 2025

Hello! I've tried to be more thorough with path normalization in v6 (vite-tsconfig-paths@next). If you could try that out and report back, I'd be grateful.

If you still have issues, try setting logFile: true to understand what's happening with each import. (It will save logs to vite-tsconfig-paths.log in your working directory)

@aleclarson aleclarson added the waiting for response The issue author needs to reply label Apr 16, 2025
@bladeSk
Copy link
Author

bladeSk commented Apr 17, 2025

Still getting the same error, unfortunately. Here's the log file from 6.0.0-beta.3 when running npm run build. Test/Test isn't even in the log file for some reason.

vite-tsconfig-paths.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: windows waiting for response The issue author needs to reply
Projects
None yet
Development

No branches or pull requests

3 participants