Module '/node_modules/.vite/deps/vue.js' does not export a default named 'default' as required.
P粉006540600
P粉006540600 2023-10-22 13:37:29
0
1
676

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粉006540600
P粉006540600

reply all(1)
P粉127901279

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 
   },
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template