现象:最近在使用rollup开发小型js插件,打包的时候报错了Error: 'default' is not exported by node_modules/qs/lib/index.js。

原因:我使用了qs包来格式化,安装了qs依赖之后引入import qs from 'qs',但是打包就报错了,因为qs是以commonjs模块的形式出现的,rollup官方文档也有提到,如下图,所以要引入rollup-plugin-commonjs插件。参考rollup-plugin-commonjs文档https://github.com/rollup/rollup-plugin-commonjs

参考:

rollup | 解决报错Error: '__moduleExports' is not exported by xxxx

rollup官方文档

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐