rollup 在 monorepo 里会报'default' is not exported 错

2021-09-29 15:18:38 +08:00
 kilims
最近在研究前端工程化,涉及到 rollup,组件库,多包管理器,尝试使用多包管理工具控制 UI 库,但遇到了问题。

单独的 ui 库工程是能正常运行的,但一旦使用多包管理器,无论是 pnpm workspace(这个确实更友好),还是 yarn workspace,都会报下面这个错

```
./components/index.ts → lib/index.main.js, lib/index.module.js...
[!] Error: 'default' is not exported by ../../node_modules/classnames/index.js, imported by ../../node_modules/antd/es/empty/index.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
../../node_modules/antd/es/empty/index.js (18:7)
16:
17: import * as React from 'react';
18: import classNames from 'classnames';
^
19: import { ConfigContext } from '../config-provider';
20: import LocaleReceiver from '../locale-provider/LocaleReceiver';
Error: 'default' is not exported by ../../node_modules/classnames/index.js, imported by ../../node_modules/antd/es/empty/index.js
at error (/Users/kilims/Documents/playground/personal/lerna_projects/node_modules/rollup/dist/shared/rollup.js:158:30)
```

看起来是 rollup 在 monorepo 的架构下,symlink 某些配置不起效,导致 commonjs 规范没法正确引入包

https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module 这个网站已经试过了,nameExportedOption 已经废弃,且也尝试了 symlink 的一些参数,始终无法获得正解(目的:正常在 monorepo 架构下跑起来)

但头疼的是没有思绪看源码进行修改,有没有 v 友有类似经验,求个解决思路
1226 次点击
所在节点    问与答
3 条回复
zixiCat
2021-09-29 17:34:32 +08:00
Maybe you can try to use this plugin "@rollup/plugin-commonjs".
zixiCat
2021-09-29 18:12:17 +08:00
尴尬,看错题目,是不是这个插件换了其他的 api 了?我之前直接默认配置就 okay 了
wuchangming89
2022-07-18 15:49:15 +08:00
也遇到了,用 workspace 就不行,楼主有没解决?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/805171

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX