-
-
Notifications
You must be signed in to change notification settings - Fork 53
-
- 以下是一段react 18 、react17的一段兼容性代码,根据判断版本调用不同的api
- 最终生成的文件内容将包引用一同提升到了顶层,会导致此判断出错
3.当引用此包的宿主环境安装的react版本为17时,编译报错如下
image
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments 3 replies
-
I think even if you keep your source code in the application side, it will still report an error.
try { const { createRoot } = require("react-dom/client"); } catch (err) { const readDOM = require("react-dom"); }
IMO, this should not be a runtime decision.
Beta Was this translation helpful? Give feedback.
All reactions
-
For example, this is how Storybook handle multiple React versions via build tool configuration https://github.com/storybookjs/storybook/blob/next/code/lib/react-dom-shim/src/preset.ts.
Beta Was this translation helpful? Give feedback.
All reactions
-
我已经通过在require中使用变量来规避这个问题,如下:
image
rslib这个行为和webpack以及其他相关工具(如@umijs/father)的行为是不一致的;希望后续会有比较好的处理方式
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Yes, it will be an issue in some scenario. We will try to fix that in the future.
Beta Was this translation helpful? Give feedback.
All reactions
-
和webpack以及其他相关工具(如@umijs/father)的行为是不一致的
This should be inconsistent with esbuild, but hoisting behaviour should be same in webpack/Rspack/Rslib. Can you show some configs of your project?
Beta Was this translation helpful? Give feedback.