the requested module 'xxxx does not provid

70 天前
 tysb777

项目框架是用 vue2 迁移到了 vite

安装了甘特图后就报错了

Uncaught SyntaxError: The requested module '/node_modules/vue-slider-component/dist/vue-slider-component.umd.min.js?v=466bd573' does not provide an export named 'default' (at Header.vue:144:8)

"gantt-elastic": "^1.0.12",
"gantt-elastic-header": "^0.1.11",

此问题在 vue cli 上不会出现。

有没有大佬知道问题出在哪里,以及如何修改。

663 次点击
所在节点    Vue.js
4 条回复
lisongeee
70 天前
这错误不是很明显吗?模块没有默认导出,从你的后缀来看这是一个 umd 模块,你用 esm 去导入自然会报错

https://github.com/NightCatSama/vue-slider-component/issues/643

将导入路径直接换成 vue-slider-component/lib/index.ts 应该就行,让 vite 再编译一次

另外为啥一个注册 6 年的账号会问这种,上 github 搜索不就出来了吗?
tysb777
70 天前
@lisongeee 感谢大佬回复,问题解决了。

vite.config.js

```
optimizeDeps: {
include: ['dayjs','vue-slider-component']
}
```
lisongeee
70 天前
你也没有用上我的方法,说不上感谢

另外我想起来 react 也是只有 umd 模块,迄今为止都没有 esm 格式

vite 应该也是通过你说的这种方式支持导入 react 的
tysb777
70 天前
@lisongeee 感谢教导!! 反省一下这六年有没有好好学习😟

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1020518

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX