【发布时间】:2020-05-12 02:30:53
【问题描述】:
尝试开始使用 Microsoft 的 Fluent UI,但由于某种原因,我收到了错误,即没有从库中导出每个组件。
跟随“开始”
npx create-react-app my-appcd my-appnpm install @fluentui/react
包.json
"dependencies": {
...
"@fluentui/react": "^7.111.1", // Note: office-ui-fabric is NOT a specified dependency
...
}
App.js
import React from 'react';
// Here I have tried 5 ways of doing the import, the first 4 are errors
// #1, from https://developer.microsoft.com/en-us/fluentui#/get-started
import { PrimaryButton } from '@fluentui/react';
// #2,3,4 are from https://github.com/microsoft/fluentui#integrating-in-your-project
// #2
import { PrimaryButton } from '@fluentui/react/lib/Button';
// #3
import { PrimaryButton } from '@fluentui/react/lib-amd/Button';
// #4
import { PrimaryButton } from '@fluentui/react/lib-commonjs/Button';
// #5, works with ESLint errors that this package is not a specified dependency
import { PrimaryButton } from 'office-ui-fabric-react'
function App() {
return (
<div className="App">
<PrimaryButton>I am a button.</PrimaryButton>
</div>
);
}
export default App;
以下是我在每个不同的导入后遇到的错误:
./src/App.js Attempted import error: 'PrimaryButton' is not exported from '@fluentui/react'.
2、3、4。Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
- 适用于预期的 linter 警告。我非常困惑为什么 Get Started 是从
@fluentui/react导入的,而文档说要从office-ui-fabric-react导入与之相矛盾
所以我的问题是:
- 为什么
import { PrimaryButton } from '@fluentui/react'不起作用,而import { PrimaryButton } from 'office-ui-fabric-react';起作用? - 我是否缺少全局安装?
- 为什么当所有入门模板都使用
office-ui-fabric-react的版本作为依赖项时,Get Started 安装@fluentui/react?
看起来yarn add office-ui-fabric-react 也会安装"office-ui-fabric-react": "^7.111.1"。所以我很好奇这是否是更正确的方法?
【问题讨论】:
-
甚至,我也面临同样的问题
标签: office-ui-fabric office-ui-fabric-react