【问题标题】:Material-Table : TypeError: Object(...) is not a function Module../node_modules/@material-ui/pickers/dist/material-ui-pickers.esm.jsMaterial-Table : TypeError: Object(...) is not a function Module../node_modules/@material-ui/pickers/dist/material-ui-pickers.esm.js
【发布时间】:2019-11-04 07:56:31
【问题描述】:

我正在尝试为我的 React 应用程序安装材料表,但是当我尝试示例代码 (https://github.com/mbrn/material-table) 时,我从模块的文件中收到一条错误消息。

我尝试更新material-ui,它是5.8.0版本。

文档中的代码:

import React, { Component } from "react";
import ReactDOM from "react-dom";
import MaterialTable from "material-table";


class App extends Component {
  render() {
    return (
      <div style={{ maxWidth: "100%" }}>
        <MaterialTable
          columns={[
            { title: "Adı", field: "name" },
            { title: "Soyadı", field: "surname" },
            { title: "Doğum Yılı", field: "birthYear", type: "numeric" },
            {
              title: "Doğum Yeri",
              field: "birthCity",
              lookup: { 34: "İstanbul", 63: "Şanlıurfa" }
            }
          ]}
          data={[
            { name: "Mehmet", surname: "Baran", birthYear: 1987, birthCity: 63 }
          ]}
          title="Demo Title"
        />
      </div>
    );
  }
}

ReactDOM.render(<App />, document.getElementById("react-div"));

错误信息:

TypeError: Object(...) is not a function
Module../node_modules/@material-ui/pickers/dist/material-ui-pickers.esm.js
39859 |   return utils;
39860 | }
39861 | 
> 39862 | var useStyles =Object(_material_ui_core_styles__WEBPACK_IMPORTED_MODULE_5__["makeStyles"])(function (theme) {                                                                                39863 |   var textColor = theme.palette.type === 'light' ? theme.palette.primary.contrastText : theme.palette.getContrastText(theme.palette.background.default);
39864 |   return {                                                           
39865 |     toolbarTxt: {

【问题讨论】:

    标签: reactjs material-ui


    【解决方案1】:

    这可能是因为您的material-table 版本与material-ui 版本不兼容。例如看看这个例子:https://codesandbox.io/s/material-ui-material-table-versioning-issue-oeqij

    @material-ui/core 版本为 3.9.3 material-table 版本为 1.39.2

    同样的错误发生:makeStyles is not a function

    但是如果你将@material-ui/core 的版本升级到4.1.2. 版本(目前最新),错误就会消失。至少这对我有帮助。我还必须将material-ui-pickers 更新为@material-ui/pickers(新名称,最新版本以避免将旧的material-ui 作为依赖项)

    【讨论】:

    • 所以我应该做的是:npm install @material-ui/core4.1.2 然后 npm install @material-ui/pickers
    【解决方案2】:

    以下应该有效:

    const MaterialTable = require("material-table");
    

    【讨论】:

    • 欢迎来到 Stack Overflow!虽然这段代码可以解决问题,including an explanation 解决问题的方式和原因确实有助于提高帖子的质量,并可能导致更多的赞成票。请记住,您正在为将来的读者回答问题,而不仅仅是现在提出问题的人。请edit您的回答添加解释并说明适用的限制和假设。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-09
    • 2019-11-10
    • 2023-03-03
    • 2020-04-25
    • 2021-01-09
    • 2020-10-30
    相关资源
    最近更新 更多