Home > Blockchain >  The requested module '/node_modules/.vite/deps/vue.js' does not provide an export named &#
The requested module '/node_modules/.vite/deps/vue.js' does not provide an export named &#

Time:07-27

The following is my problem. I packaged my project through vite in library mode. The error occurs whenever my library includes any third party UI library (e.g vue-loading-overlay). But other libraries like moment.js will have no problem.

This is my vite.config.js, Is there any problem 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" },
        },
      ],
    },
  },
});

enter image description here

CodePudding user response:

Finally I resolved my problem, Adding the following 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 
   },
}

CodePudding user response:

Refer to vuejs 3 documentation to import vue.

  • Related