Uncaught TypeError: Object(...) is not a function at useAutocomplete (useAutocomplete.js:241)

Posted

技术标签:

【中文标题】Uncaught TypeError: Object(...) is not a function at useAutocomplete (useAutocomplete.js:241)【英文标题】: 【发布时间】:2020-07-02 14:54:09 【问题描述】:

我正在开发带有材料 ui 组件的 react js 应用程序。 在我的应用程序中,我没有使用 redux。

一切正常。但是当我尝试实现材料 ui 自动完成时,它在 webpack 中不起作用。它抛出了这个错误

这是我尝试添加到我的应用程序的示例代码。 https://codesandbox.io/s/test-material-ui-autocomplete-o3uic

Uncaught TypeError: Object(...) is not a function
    at useAutocomplete (useAutocomplete.js:241)
    at Autocomplete (Autocomplete.js:382)
    at renderWithHooks (react-dom.development.js:2876)
    at updateForwardRef (react-dom.development.js:3032)
    at beginWork$1 (react-dom.development.js:3453)
    at htmlUnknownElement.callCallback (react-dom.development.js:124)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:144)
    at invokeGuardedCallback (react-dom.development.js:159)
    at beginWork$$1 (react-dom.development.js:4397)
    at performUnitOfWork (react-dom.development.js:4195)

这些是我在我的应用程序中安装的包


 "dependencies": 
    "@babel/core": "^7.8.0",
    "@babel/plugin-proposal-class-properties": "^7.8.0",
    "@babel/preset-react": "^7.8.0",
    "@babel/runtime": "^7.0.0-beta.55",
    "@fortawesome/fontawesome-svg-core": "^1.2.26",
    "@fortawesome/free-solid-svg-icons": "^5.12.0",
    "@fortawesome/react-fontawesome": "^0.1.8",
    "@material-ui/core": "^4.8.3",
    "@material-ui/icons": "^4.5.1",
    "@material-ui/lab": "^4.0.0-alpha.45",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.0",
    "@testing-library/user-event": "^7.2.1",
    "autosuggest-highlight": "^3.1.1",
    "axios": "^0.19.2",
    "babel-loader": "^8.0.6",
    "bootstrap": "^4.4.1",
    "css-loader": "^3.4.2",
    "downshift": "^4.0.4",
    "file-loader": "^5.0.2",
    "file-saver": "^2.0.2",
    "html-webpack-plugin": "^3.2.0",
    "jquery": "^3.4.1",
    "material-icons-react": "^1.0.4",
    "mui-datatables": "^2.0.0",
    "notistack": "^0.9.7",
    "npm": "^6.13.6",
    "path": "^0.12.7",
    "react": "^16.13.1",
    "react-app-polyfill": "^1.0.5",
    "react-autosuggest": "^9.4.3",
    "react-countdown-circle-timer": "^1.0.6",
    "react-dom": "^16.12.0",
    "react-excel-workbook": "0.0.4",
    "react-html-table-to-excel": "^2.0.0",
    "react-idle-timer": "^4.2.12",
    "react-loader-spinner": "^3.1.5",
    "react-material-ui-form-validator": "^2.0.9",
    "react-responsive": "^8.0.1",
    "react-router": "^5.1.2",
    "react-router-dom": "^5.1.2",
    "react-scripts": "^3.3.0",
    "react-virtualized": "^9.21.2",
    "react-xlsx-workbook-dynamic-column-width": "0.0.2",
    "reactstrap": "^8.2.0",
    "style-loader": "^1.1.2",
    "styled-components": "^4.4.1",
    "webpack": "^4.41.5",
    "webpack-cli": "^3.3.10",
    "webpack-dev-server": "^3.10.1"
  ,

请帮帮我。

【问题讨论】:

我正在尝试复制您演示中的错误,但我不能,我需要做什么? @bernardo,当我在 webpack 和 babel 中使用它时只会抛出错误 【参考方案1】:

我自己也遇到了这个确切的错误。 @material-ui/lab@4.0.0-alpha.45 具有 @material-ui/core@^4.9.0 的对等依赖关系,他们显然似乎真的是这个意思。你似乎锁定在@material-ui/core@^4.8.3,我建议升级:

yarn upgrade @material-ui/core@^4.9.0

查看确切的package.jsonhere。

【讨论】:

以上是关于Uncaught TypeError: Object(...) is not a function at useAutocomplete (useAutocomplete.js:241)的主要内容,如果未能解决你的问题,请参考以下文章

如何解决问题:Uncaught (in promise) TypeError: promisify is not a function?

Uncaught TypeError

Uncaught TypeError: Cannot redefine property: $router

Uncaught TypeError: o.block is not a function

Laravel 5.1 和 Vue.js - 21678 Uncaught (in promise) TypeError: Cannot read property 'data' of null

jQuery Post blob 对象给出 Uncaught TypeError: Illegal invocation