I'm facing a strange issue while trying to use path aliases (~/utils/assets) in my Vue 3 SFC (single file component) file. I am using the Volar VS Code plugin, and the issue occurs even after enabling "Takeover mode" with the Volar plugin.
- As you can see in the screenshot below, the
Home.vuefile is able to referenceimport { zipFromImages } from "~/utils/assets";without any issues. However thePreview.vuefile—which is located in the same directory asHome.vue—is NOT, and throws the ts(2307) error:Cannot find module '~/utils/assets' or its corresponding type declarations.ts(2307). - When I select the
Preview.vuefile (a Vue SFC.vuefile), the bottom of VS Code shows "No tsconfig". When I selectHome.vuefile, it properly shows "tsconfig.json" there and links to mytsconfig.jsonfile as expected.
Has anyone else faced these issues and found a solution?
What I've tried
- [x] Followed official Vue + TypeScript instructions
- [x] Using latest VS Code & plugin versions
- [x] Using latest NPM packages
Configuration
tsconfig.json
{
"compilerOptions": {
"target": "es6",
"lib": [
"es6",
"dom"
],
"outDir": "./dist",
"module": "esnext",
"isolatedModules": true,
"strict": true,
"skipLibCheck": true,
"esModuleInterop": true,
"moduleResolution": "node",
"noUnusedLocals": true,
"noImplicitAny": true,
"allowJs": true,
"resolveJsonModule": true,
"baseUrl": "./",
"paths": {
"@/*": [
"./src/ui/*"
],
"~/*": [
"./src/ui/*"
]
},
"typeRoots": [
"./node_modules/@types",
"./node_modules/@figma"
]
},
"include": [
"src/**/*.ts",
"src/**/*.d.ts",
"src/**/*.tsx",
"src/**/*.vue"
],
"exclude": [
"node_modules",
"dist"
]
}
vite.config.ts
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { viteSingleFile } from "vite-plugin-singlefile";
import path from "path";
export default defineConfig(({ mode }) => {
const isDev = mode === "development";
return {
plugins: [vue(), viteSingleFile()],
resolve: {
alias: {
"@": path.resolve(__dirname, "src/ui"),
"~": path.resolve(__dirname, "src/ui"),
},
},
build: {
outDir: path.resolve(__dirname, "dist/ui"), // The output directory
minify: !isDev,
sourcemap: true,
watch: isDev
? {
exclude: ["dist", "node_modules"],
}
: null,
target: "esnext",
assetsInlineLimit: 100000000,
chunkSizeWarningLimit: 100000000,
cssCodeSplit: false,
brotliSize: false,
rollupOptions: {
output: {
manualChunks: () => "everything.js",
},
inlineDynamicImports: true,
},
},
};
});
Version information
VS Code & VS Code plugins
- VS Code 1.65.2
- Vue Language Features (Volar) v0.33.2
- TypeScript Vue Plugin (Volar) v0.33.2
NPM Packages
- Vite 2.8.6
- Vue 3.2.6
- Typescript 4.6.2
- @vue/compiler-sfc 3.2.6
- @vitejs/plugin-vue 2.2.4
- vite-plugin-singlefile 0.7.1
