Home  >  Q&A  >  body text

Module '/node_modules/.vite/deps/vue.js' does not export a default named 'default' as required.

The following are my questions. I packaged my project in library mode via vite. Whenever my library includes any third party UI library like vue-loading-overlay, the error occurs. But other libraries like moment.js won’t have a problem.

This is my vite.config.js, is there something wrong with my configuration?

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" },
        },
      ],
    },
  },
});
P粉006540600P粉006540600363 days ago622

reply all(1)I'll reply

  • P粉127901279

    P粉1279012792023-10-23 09:05:10

    Finally I solved my problem by adding the following content in vite.config.js. It works for me.

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

    reply
    0
  • Cancelreply