我有一个 React 应用程序,我使用 Parcel 作为我的打包器。我想使用“office-ui-fabric-react”组件。一切工作正常,直到我从“office-ui-fabric-react”(Office Fabric Ui)导入组件。
这是我从控制台收到的错误消息 -
TypeError: can't redefine non-configurable property "ChoiceGroupOption".
我已确保安装了所有依赖项(“office-UI-fabric-react”不需要任何声明的依赖项)。
然后,我设置了一个新的 React 项目,这次使用 Create-React-App 命令生成样板文件。这个版本没有任何问题,即使从“office-ui-fabric-react”导入组件后也可以正常工作
import { PrimaryButton } from "office-ui-fabric-react
//只需使用parcel将此行添加到Reactjs项目
TypeError: can't redefine non-configurable property "ChoiceGroupOption"
最佳答案
根据@VitalieBraga的建议,这个问题的解决方案是为每个要导入的office-UI React组件引用特定的模块。 例如
import { PrimaryButton } from "office-ui-fabric-react/lib/button";
import { ChoiceGroup,IChoiceGroupOption} from "office-ui-fabric-react/lib/ChoiceGroup";
这实际上解决了我遇到的问题,但就单行导入多个组件的问题而言,这是 Parcel 不可能实现的。
import { css, classNamesFunction, DefaultButton, IStyle, Label, PrimaryButton } from 'office-ui-fabric-react';
另一种选择是使用 Webpack 来代替 Parcel
关于reactjs - 如何在 React.js 应用程序中解析 "non-configurable property "ChoiceGroupOption",我使用 Parcel 并从 "office-ui-fabric-react"导入 comp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56333658/