Material-Table:TypeError:Object(...)不是功能Module ../ node_modules/@material-ui/pickers/dist/material-ui-pickers.esm.js

时间:2019-06-21 12:54:47

标签: reactjs material-ui

我正在尝试为我的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: {

2 个答案:

答案 0 :(得分:1)

以下方法应该起作用:

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

答案 1 :(得分: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作为依赖项)