The requested module '/node_modules/.vite/deps/vue.js' does not provide an export named 'default'

Viewed 3365

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

3 Answers

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 
   },
}

Original Answer

"Chart.js V3 is treeshakable so you need to import and register everything or if you want everything you need to import the chart from the auto import like so:

change import Chart from 'chart.js' to ->

import Chart from 'chart.js/auto';

For more information about the different ways of importing and using chart.js you can read the integration page in the docs.

Since you are upgrading from Chart.js V2 you might also want to read the migration guide since there are some major breaking changes between V2 and V3"

Refer to vuejs 3 documentation to import vue.

Related