【问题标题】:The requested module '/node_modules/.vite/deps/vue.js' does not provide an export named 'default'请求的模块 \'/node_modules/.vite/deps/vue.js\' 不提供名为 \'default\' 的导出
【发布时间】:2022-11-16 18:11:45
【问题描述】:

以下是我的问题。 我通过库模式通过vite打包了我的项目。只要我的库包含任何第三方 UI 库(例如 vue-loading-overlay),就会发生错误。但是像 moment.js 这样的其他库就没有问题了。

这是我的vite.config.js,我的配置有问题吗?

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

export default defineConfig({
  plugins: [vue()],
  build: {
    lib: {
      entry: resolve(__dirname, "src/lib.ts"),
      name: "my-ui-lib",
      fileName: "my-ui-lib",
    },
    rollupOptions: {
      external: ["vue"],
      output: [
        {
          format: "es",
          exports: "named",
          globals: { vue: "vue" },
        },
      ],
    },
  },
});

【问题讨论】:

    标签: vue.js vite rollup


    【解决方案1】:

    最后我解决了我的问题,在 vite.config.js 中添加以下内容。这个对我有用。

    build: {
    
       /** If you set esmExternals to true, this plugins assumes that 
         all external dependencies are ES modules */
    
       commonjsOptions: {
          esmExternals: true 
       },
    }
    

    【讨论】:

      【解决方案2】:

      Original Answer

      “Chart.js V3 是 treeshakable,所以你需要导入和注册所有东西,或者如果你想要你需要的一切,你可以从自动导入中导入图表,如下所示:

      改变 import Chart from 'chart.js' 至 ->

      import Chart from 'chart.js/auto';

      有关导入和使用 chart.js 的不同方式的更多信息,您可以阅读文档中的集成页面。

      由于您是从 Chart.js V2 升级,您可能还想阅读迁移指南,因为 V2 和 V3 之间有一些重大的重大变化”

      【讨论】:

        【解决方案3】:

        /* Adding the following in vite.config.js. Just copy and paste all these code. It works for me. */

        import { defineConfig } from "vite";
        import react from "@vitejs/plugin-react";
        
        
        // https://vitejs.dev/config/
        export default defineConfig({
           plugins: [react()],
           commonjsOptions: {
              esmExternals: true,
           },
        });
        

        【讨论】:

          【解决方案4】:

          参考vuejs 3文档导入vue。

          【讨论】:

          • 您的答案可以通过其他支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写出好的答案的信息in the help center
          猜你喜欢
          • 2022-08-10
          • 2021-11-07
          • 2022-06-19
          • 1970-01-01
          • 2021-11-02
          • 2022-01-25
          • 2023-02-02
          • 2021-10-03
          • 1970-01-01
          相关资源
          最近更新 更多