Skip to content
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

Doesn't work with Vite 2 #6

Closed
IlyaSemenov opened this issue Jan 19, 2021 · 3 comments
Closed

Doesn't work with Vite 2 #6

IlyaSemenov opened this issue Jan 19, 2021 · 3 comments

Comments

@IlyaSemenov
Copy link

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
Copy link
Owner

Use vite-tsconfig-paths@2 instead

@scambier
Copy link

scambier commented Jan 20, 2021

@aleclarson its doesn't seem to work.

  • Create a new project with npm init @vitejs/app <project-name>
  • Add the following to tsconfig.json in compilerOptions:
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    }
  • Install vite-tsconfig-paths 2.0.0
  • Add it to vite.config.ts:
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
  plugins: [vue(), tsconfigPaths()]
})
  • Update App.vue to import HelloWorld.vue with @/:
import HelloWorld from '@/components/HelloWorld.vue'
  • Result:

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 vitejs/vite#88 (comment) works, but I'd rather your use your plugin to avoid keeping both files in sync when I'll add more aliases :)

@aleclarson
Copy link
Owner

aleclarson commented Jan 20, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants