SoFunction
Updated on 2025-04-05

"default" appears in vite package, is not exported by "node_modules/... Problem solved

Project scenario:

vue3+ts+vite project package

Problem description

error during build:
RollupError: "default" is not exported by "node_modules/vue/dist/", imported by "node_modules/@kangc/v-md-editor/lib/".
    at error (file:///D:...

Cause analysis:

vite does not support commonjs syntax, it needs to be used@rollup/plugin-commonjsPlugin, Rollup plugin for converting CommonJS modules to ES6 modules.

Solution:

1. Installation@rollup/plugin-commonjsPlugin

npm i @rollup/plugin-commonjs

2. Add this plugin to the configuration. Note that commonjs() must be on it, otherwise it may not take effect. I have been checking for a long time

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import commonjs from '@rollup/plugin-commonjs';//Introduce commojs
export default defineConfig({
  plugins: [
    commonjs() as any,
    vue(),
  ],
 }

Summarize

This article about vite packaging appears "default" is not exported by "node_modules/...This is the end of this article about problem solving. For more related vite packaging problem solving content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!