在nuxt3+naiveui项目中打包出现vueuc导入方式问题报错,导致页面访问500。
错误描述
[nuxt] [request error] [unhandled] [500] Named export 'VBinder' not found. The requested module 'vueuc' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'vueuc';
const { resizeObserverManager, VResizeObserver, VirtualList, VFollower, VBinder, VTarget, VOverflow, VFocusTrap } = pkg;
解决方式:
在 nuxt.config.ts
文件中添加如下代码:
build: { transpile: ['naive-ui', "vueuc"] },