用vite创建的vue3项目,用@来代替src不生效。报错:[vite] Internal server error: Failed to resolve import "@/views/xxxxxxxxxxxxx" from "src\views\dashboard\index.vue". Does the file exist?
解决的方法是:
- 先安装path
npm install --save -dev @type/node
- 在vite.config.js文件中,添加相应的配置
1 import { resolve } from 'path' 2 3 export default defineConfig({ 4 plugins: [ 5 vue(), 6 ], 7 8 resolve:{ 9 alias:{ 10 '@':resolve('src') 11 } 12 } 13 })
- 最后npm i 一下依赖,重新运行项目就可以使用@了
标签:src,resolve,views,vue3,import,vite From: https://www.cnblogs.com/NUNA/p/17495822.html