vue3+ vite => '默认值'不是由xxx导出

发布于 2025-02-07 14:29:04 字数 780 浏览 3 评论 0原文

不是一个问题,而是一个解决方案,因此它可以帮助他人或未来的自我!

我花了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乙白 2025-02-14 14:29:04

不要针对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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文