我试图将 Office UI Fabric React Components 添加到一个 现有项目 中。我的项目是通过 Visual Studio 2019 创建的新 ASP.NET Core Web 应用程序。此项目是使用 ASP.NET Core 3.0(预览版 7)通过 React.js 和 Redux 模板创建的。启动后,我按照 Fabric React - Add to Existing Project docs 进行了操作。
请注意:在添加Office UI Fabric React组件之前,该应用程序运行良好。
- 我在已创建的 web 项目中导航到
ClientApp
目录。 - 执行了
npm install office-ui-fabric react --save
。结果发现存在超过 1,000 个漏洞。 - 打开了
./ClientApp/src/components/Home.tsx
文件。 - 添加了一行 `import {PrimaryButton} from 'office-ui-fabric-react';`。
- 运行该应用程序。
这会生成以下错误:
Failed to compile
Type error: Namespace 'React' has no exported member 'ElementType'. TS2694
15 | * Slottable version of React.ReactType
16 | */
17 | export declare type ISlottableReactType<TProps extends ValidProps, TShorthandPromp extends ValidShorthand> = React.ElementType<TProps> & ISlotCreator<TProps, TShorthandProp>;
|
18 | /**
19 | * Props generated by Foundation.
20 | */
请注意:在添加Office UI Fabric React组件之前,该应用程序运行良好。
@types/react
上,但是它被设置为版本16.7.18。如果我将它更改为16.8+,那么基本上就会打开一个依赖和代码更改的兔子洞。这意味着出现了问题。 - Some User@types/react
大于等于16.8,以避免类型错误。如果您的项目在使用React 16.8时出现错误,您可以将其升级以支持16.8或使用Fabric 6。您还可以使用命令npm init uifabric
(然后是yarn
和yarn start
)来查看如何在示例存储库中使用Fabric。 - Jason Gore