V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
kilims
V2EX  ›  问与答

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

  •  
  •   kilims · Sep 29, 2021 · 2148 views
    This topic created in 1672 days ago, the information mentioned may be changed or developed.
    最近在研究前端工程化,涉及到 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 友有类似经验,求个解决思路
    3 replies    2022-07-18 15:49:15 +08:00
    zixiCat
        1
    zixiCat  
       Sep 29, 2021
    Maybe you can try to use this plugin "@rollup/plugin-commonjs".
    zixiCat
        2
    zixiCat  
       Sep 29, 2021
    尴尬,看错题目,是不是这个插件换了其他的 api 了?我之前直接默认配置就 okay 了
    wuchangming89
        3
    wuchangming89  
       Jul 18, 2022
    也遇到了,用 workspace 就不行,楼主有没解决?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3989 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 00:52 · PVG 08:52 · LAX 17:52 · JFK 20:52
    ♥ Do have faith in what you're doing.