vue3+ vite => '默认值'不是由xxx导出
不是一个问题,而是一个解决方案,因此它可以帮助他人或未来的自我!
我花了3天的时间尝试使用VITE迁移/构建VUE3项目并遇到此错误:
'default' is not exported by XXX
我正在动态导入资产,如这里所述: https://vitejs.s.dev/guide/guide/assets。 html#new-url-url-import-meta-url
new URL(`/src/${path}`, import.meta.url).href;
path
是我资产的路径,例如“ Assets/icons/icons/xxx.svg
” 。
问题是,如果新的url()基本路径针对src
文件夹,则Vite将尝试解决.vue
和.ts
Files 。它会生成上述错误。
要解决它,只需在URL解决的基本路径上添加“资产”文件夹,就像这样:
new URL(`/src/assets/${path}`, import.meta.url).href;
不客气,我很高兴我!
Not a question but a solution so it may help others nor futur self !
I've spent 3 days trying to migrate/build a Vue3 project with Vite and having this error:
'default' is not exported by XXX
I'm importing assets dynamically as explained here:
https://vitejs.dev/guide/assets.html#new-url-url-import-meta-url
new URL(`/src/${path}`, import.meta.url).href;
path
being the path to my asset, for example "assets/icons/xxx.svg
".
Problem is, if the new URL() base path targets the src
folder, Vite will try to resolve the .vue
and .ts
files within it which generates the error above.
To solve it, just add the "assets" folder on the base path of the URL resolving, like so:
new URL(`/src/assets/${path}`, import.meta.url).href;
You're welcome futur me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要针对URL构造函数上的整个
src
文件夹。设置“资产”文件夹,以便在尝试解决动态资产时不会尝试解决您的.ts/.js/.vue文件。
Don't target the whole
src
folder on the URL constructor.Set the "assets" folder so it does not try to resolve your .ts/.js/.vue files when trying to resolve dynamic assets.