aleclarson / vite-tsconfig-paths

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

Doesn't work with Vite 2 #6

Closed IlyaSemenov closed 3 years ago

IlyaSemenov commented 3 years ago

The plugin doesn't work with Vite 2:

failed to load config from /xxx/vite.config.ts
error when starting dev server:
Error: Cannot find module 'vite/dist/node/resolver'
Require stack:
- /xxx/node_modules/vite-tsconfig-paths/dist/index.js
- /xxx/vite.config.ts

It also seems that resolvers is not more a valid property at vite.UserConfig.

aleclarson commented 3 years ago

Use vite-tsconfig-paths@2 instead

scambier commented 3 years ago

@aleclarson its doesn't seem to work.

export default defineConfig({ plugins: [vue(), tsconfigPaths()] })


- Update App.vue to import HelloWorld.vue with `@/`:
```ts
import HelloWorld from '@/components/HelloWorld.vue'

image

My full package.json, for reference:

{
  "name": "my-project",
  "version": "0.0.0",
  "scripts": {
    "dev": "vite",
    "build": "vuedx-typecheck . && vite build"
  },
  "dependencies": {
    "vue": "^3.0.5"
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "^1.0.4",
    "@vue/compiler-sfc": "^3.0.5",
    "@vuedx/typecheck": "^0.4.1",
    "@vuedx/typescript-plugin-vue": "^0.4.1",
    "typescript": "^4.1.3",
    "vite": "^2.0.0-beta.12",
    "vite-tsconfig-paths": "^2.0.0"
  }
}

Edit: the solution from https://github.com/vitejs/vite/issues/88#issuecomment-762415200 works, but I'd rather your use your plugin to avoid keeping both files in sync when I'll add more aliases :)

aleclarson commented 3 years ago

@scambier See #4. The path mapping should only apply to lang="ts" scripts in .vue modules, but it's not implemented yet.