【问题标题】:TypeError: (0 , Rt.useState) is not a functionTypeError: (0 , Rt.useState) 不是函数
【发布时间】:2022-01-22 15:07:13
【问题描述】:

在标记为重复之前,我已经搜索了很多,没有答案。

我正在制作一个反应项目。在开发环境中,一切正常。然后我构建react的时候,浏览器出现这个错误:

TypeError: (0 , Rt.useState) is not a function at react-dom.production.min.js:209

在互联网上我搜索了很多。每个人都会参考没有钩子的版本16.7。不过我有版本16.14!看看依赖关系:

{
  "qs": "^6.10.2",
  "react": "^16.14.0",
  "react-content-loader": "^6.1.0",
  "react-dom": "^16.14.0",
  "react-intersection-observer": "^8.33.1",
  "react-qr-reader": "^2.2.1",
  "react-router-dom": "^5.3.0",
  "react-scripts": "5.0.0",
  "react-swipeable-list": "^1.4.0",
  "react-tiger-transition": "^4.1.2",
  "react-toastify": "^8.1.0",
  "react-transition-group": "^4.3.0"
}

我已经检查了 react 中的重复项。我用npm ls reactnpm ls react-dom

这是这两个的结果:

> npm ls react

+-- react-content-loader@6.1.0
| `-- react@16.14.0 deduped
+-- react-dom@16.14.0
| `-- react@16.14.0 deduped
+-- react-intersection-observer@8.33.1
| `-- react@16.14.0 deduped
+-- react-qr-reader@2.2.1
| `-- react@16.14.0 deduped
+-- react-router-dom@5.3.0
| +-- react-router@5.2.1
| | +-- mini-create-react-context@0.4.1
| | | `-- react@16.14.0 deduped
| | `-- react@16.14.0 deduped
| `-- react@16.14.0 deduped
+-- react-scripts@5.0.0
| `-- react@16.14.0 deduped
+-- react-swipeable-list@1.4.0
| `-- react@16.14.0 deduped
+-- react-tiger-transition@4.1.2
| `-- react@16.14.0 deduped
+-- react-toastify@8.1.0
| `-- react@16.14.0 deduped
+-- react-transition-group@4.4.2
| `-- react@16.14.0 deduped
`-- react@16.14.0

还有一个:

> npm ls react-dom

+-- react-dom@16.14.0
+-- react-qr-reader@2.2.1
| `-- react-dom@16.14.0 deduped
+-- react-swipeable-list@1.4.0
| `-- react-dom@16.14.0 deduped
+-- react-toastify@8.1.0
| `-- react-dom@16.14.0 deduped
`-- react-transition-group@4.4.2
  `-- react-dom@16.14.0 deduped

所以我们可以说没有重复!

语法可能是正确的,因为它在开发中工作得很好。

我很困惑。 谢谢。

【问题讨论】:

    标签: javascript reactjs use-state production react-dom


    【解决方案1】:

    #SOLVED 问题是因为 vs code intellisense 自动添加了这个:

    import { useState } from 'react/cjs/react.development.js'
    

    而不是

    import { useState } from 'react'
    

    杀了我才找到它:/

    【讨论】:

      猜你喜欢
      • 2020-03-03
      • 1970-01-01
      • 2022-01-08
      • 2021-06-30
      • 2020-08-04
      • 2021-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多