首页 > 其他分享 >vite不能用@做为路径的解决方法

vite不能用@做为路径的解决方法

时间:2022-11-12 01:55:27浏览次数:37  
标签:resolve 路径 vue vitejs 解决 import config vite

vite创建vue3后,发现原来用@做为路径的不能用了,报错信息是

Internal server error: Failed to resolve import "@

在网上查了一下资料,解决方法如下

首先安装path

npm install --save-dev @types/node

找到vite.config.js文件,添加信息

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve:{
    alias:{
      '@':resolve('src')
    }
  }
})

最后

npm install

问题解决

标签:resolve,路径,vue,vitejs,解决,import,config,vite
From: https://www.cnblogs.com/youyuan1980/p/16882567.html

相关文章