【问题标题】:install material-ui in visual studio react project在visual studio react项目中安装material-ui
【发布时间】:2017-10-17 19:47:46
【问题描述】:

我不熟悉使用 npm 并在 Visual Studio 中做出反应。尝试为我的 React 项目安装 Material-UI@next,但在运行项目时收到这些警告。

[at-loader] ./node_modules/material-ui/ButtonBase/ButtonBase.d.ts:12:11 
TS2694: Namespace 'React' has no exported member 'ButtonHTMLAttributes'.
[at-loader] ./node_modules/material-ui/ButtonBase/ButtonBase.d.ts:13:9 
TS2694: Namespace 'React' has no exported member 'AnchorHTMLAttributes'.
[at-loader] ./node_modules/material-ui/Chip/Chip.d.ts:4:18 
TS2430: Interface 'ChipProps' incorrectly extends interface 'HTMLAttributes<HTMLDivElement>'.
Types of property 'label' are incompatible.
Type 'ReactNode' is not assignable to type 'string | undefined'.
  Type 'null' is not assignable to type 'string | undefined'.
[at-loader] ./node_modules/material-ui/Form/FormControl.d.ts:5:17 
TS2694: Namespace 'React' has no exported member 'HtmlHTMLAttributes'.
[at-loader] ./node_modules/material-ui/Form/FormControlLabel.d.ts:13:11 
TS2694: Namespace 'React' has no exported member 'LabelHTMLAttributes'.
...

我遗漏了什么明显的东西?

【问题讨论】:

  • 您是否使用 AMD 模块加载器(即 CommonJS 或 RequireJS)?...
  • 不,我不这么认为。我正在使用 webpack 来打包 js 文件。该项目基于 Visual Studio 模板“React.js 和 Redux”,到目前为止我所做的唯一更改是添加 Material-UI。
  • 什么版本的visual studio?
  • Visual Studio 社区 2017,版本 15.3.5

标签: visual-studio reactjs material-ui


【解决方案1】:

让最新的 Material-UI 与 .Net core 的“react/redux”模板一起工作时,我遇到了完全相同的问题。我发现这是按顺序获取正确版本的依赖项的问题。

为了让它正常工作,我将所有的包都更新到了最新版本:

$ npm install -g npm-check-updates $ npm-check-updates -u $ npm install

一旦我更新了这些参考,一些示例代码就坏了。所以我只是简单地删除了损坏的部分,因为我所关心的只是让 Material-UI 正常工作。

一旦我有了那个部分,我只需要进行正确的导入并能够使用 Paper 元素。

这是我如何使用它的示例。

https://github.com/cbehrends/MaterialUI_DotNetCore.git

祝你好运!

编辑: 我已经更新了 repo 并修复了我发现的任何版本问题。我会尽力保持这个 repo 的更新。干杯!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-23
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 2016-09-20
    • 1970-01-01
    • 2017-10-14
    相关资源
    最近更新 更多