Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 756
JoeH Avatar asked Feb 15 '26 05:02

JoeH


2 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 
   },
}
like image 184
JoeH Avatar answered Feb 17 '26 20:02

JoeH


react-pdf v6 has a pretty clever solution for this, look at their entry files. I think the point is to link to the correct file, somehow there's no need to "actually" import the worker (it doesn't run on main thread anyway I guess? New to worker and pdfjs).

import * as pdfjs from 'pdfjs-dist/build/pdf';

pdfjs.GlobalWorkerOptions.workerSrc = new URL('pdfjs-dist/build/pdf.worker.js', import.meta.url);

import.meta availability.

like image 37
Minh Nghĩa Avatar answered Feb 17 '26 20:02

Minh Nghĩa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!