Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cjs require error #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

shijistar
Copy link

我使用的框架是@umijs/max v4.0.89,打开了fastRefreshmfsu.

.umirc.ts

import { defineConfig } from 'umi';

export default defineConfig({
  fastRefresh: true,
  mf: {
    name: 'mf_foo_bar',
    shared: {
      react: { singleton: true, eager: true },
      'react-dom':{ singleton: true, eager: true },
      'react-router': { singleton: true, eager: true },
      'react-router-dom': { singleton: true, eager: true }
    },
  },
  mfsu: { strategy: 'normal' }
});

当npm包引用链混合了cjses时,就会报错,提示 __webpack_require__.$Refresh$ 为空。
iShot_2023-12-07_16 27 19
例如,在代码中引用了foo三方库,foo中使用require('bar')引用了bar,而bar是个es模块,再import模块就会报错。
简单一些,app.tsx -> import 'foo' -> require('bar') -> import 'baz' -> 💥

出错原因主要还是没有判断 __webpack_require__.$Refresh$ 是否为空,所以我开了一个PR,改动也很简单,就是在开头和末尾的注入代码,包了一层为空判断。

我对webpack不是很精通,反正这么修改在我的项目里不报错了,请审核一下是否需要merge进来吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant