目录问题描述原因分析解决方案总结问题描述 近日尝试使用vite+vue3+vant开发项目过程中,参考vant官网开发指南->快速上手->引入组件 按照上述配置好后,运
近日尝试使用vite+vue3+vant开发项目过程中,参考vant官网开发指南->快速上手->引入组件
按照上述配置好后,运行vite环境报错:Failed to resolve import
根据报错信息,发现是vant的样式引入路径不对。
程序解析为:项目路径/node_modules/vant/lib/vant/es/组件/style
实际应该是:项目路径/node_modules/vant/lib/ vant/es/组件/style
多了一个vant/lib路径。
在vite.config.js文件中解析至正确路径。
vant官网的代码如下:
在styleImport内添加代码块:
libs: [
{
libraryName: 'vant',
esModule: true,
resolveStyle: name => `../es/${name}/style`
}
]
完整代码如下:
import Vue from '@vitejs/plugin-vue';
import styleImport, { VantResolve } from 'vite-plugin-style-import';
export default {
plugins: [
vue(),
styleImport({
resolves: [VantResolve()],
libs: [
{
libraryName: 'vant',
esModule: true,
resolveStyle: name => `../es/${name}/style`
}
]
}),
],
};
修改后,重新运行vite,问题解决。
到此这篇关于vue3+vite项目中按需引入vant报错:Failed to resolve import解决的文章就介绍到这了,更多相关vue3 vite报错Failed to resolve import内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: vue3+vite项目中按需引入vant报错:Failed to resolve import的解决方案
本文链接: https://www.lsjlt.com/news/175716.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-01-12
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
2023-05-20
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0