V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
tysb777
V2EX  ›  Vue.js

the requested module 'xxxx does not provid

  •  
  •   tysb777 · 55 天前 · 637 次点击
    这是一个创建于 55 天前的主题,其中的信息可能已经有所发展或是发生改变。

    项目框架是用 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 上不会出现。

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

    4 条回复    2024-03-04 18:36:24 +08:00
    lisongeee
        1
    lisongeee  
       55 天前
    这错误不是很明显吗?模块没有默认导出,从你的后缀来看这是一个 umd 模块,你用 esm 去导入自然会报错

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

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

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

    vite.config.js

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

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

    vite 应该也是通过你说的这种方式支持导入 react 的
    tysb777
        4
    tysb777  
    OP
       55 天前 via iPhone
    @lisongeee 感谢教导!! 反省一下这六年有没有好好学习😟
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3324 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 113ms · UTC 11:24 · PVG 19:24 · LAX 04:24 · JFK 07:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.