aleclarson / vite-tsconfig-paths

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

tsconfig absolute paths not working in QWIK #66

Closed devagja closed 1 year ago

devagja commented 1 year ago

https://github.com/BuilderIO/qwik/issues/1144

Qwik Version "@builder.io/qwik": "0.0.105", "@builder.io/qwik-city": "0.0.105",

Operating System (or Browser) Win 11

Node Version (if applicable) 16.16.0

Actual Behaviour vite.config

import { defineConfig } from 'vite'
import { qwikVite } from '@builder.io/qwik/optimizer'
import { qwikCity } from '@builder.io/qwik-city/vite'
import netlifyEdge from '@netlify/vite-plugin-netlify-edge'

import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig(() => {
  return {
    plugins: [
      tsconfigPaths(),
      qwikCity(),
      qwikVite({ ssr: { outDir: 'netlify/edge-functions/entry.netlify' } }),
      netlifyEdge({ functionName: 'entry.netlify' })
    ]
  }
})

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2017",
    "module": "ES2020",
    "lib": ["es2020", "DOM"],
    "jsx": "react-jsx",
    "jsxImportSource": "@builder.io/qwik",
    "strict": true,
    "resolveJsonModule": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "incremental": true,
    "types": ["vite/client"],
    "baseUrl": ".",
    "paths": {
      "@components/*": ["./src/components/*"],
      "@routes/*": ["./src/routes/*"],
      "@styles/*": ["./src/styles/*"],
      "@icons/*": ["./src/icons/*"],
      "@icons_jsx/*": ["./src/icons_jsx/*"],
      "@src/*": ["./src/*"],
      "@data/*": ["./src/data/*"],
      "@sections/*": ["./src/sections/*"],
      "@navigation/*": ["./src/navigation/*"],
      "@public/*": ["./public/*"]
    }
  }
}

The error [vite] Internal server error: Failed to resolve import "@sections/Contact" from "src\routes_component_nhdyifbjneq.js". Does the file exist? [vite] ✨ optimized dependencies changed. reloading [vite] Error when evaluating SSR module /src/routes_component_nhdyifbjneq.js: Error: Cannot find module '@sections/Contact' imported from 'xxxxxxx/src/routes_component_nhdyifbjneq.js'

I think the problem comes from SSR, which is not suportted the absolute paths yet

devagja commented 1 year ago

"allowJs": true was missing on tsconfig, which is documented in

https://github.com/aleclarson/vite-tsconfig-paths