reactjs - 使用情绪/反应的组件包时出现运行时错误“对象(...)不是函数”
问题描述
我有一个引入了@emotion/react@v11.x 的组件库。我现在正在尝试升级我的 ui 项目以使用该新包,但我遇到了一个运行时错误,该错误似乎与情绪如何消耗反应有关。
emotion-element-4fbd89c5.browser.esm.js:28 Uncaught TypeError: Object(...) is not a function
at eval (emotion-element-4fbd89c5.browser.esm.js:28)
at Object.../node_modules/@emotion/react/dist/emotion-element-4fbd89c5.browser.esm.js (index.js:944)
at __webpack_require__ (index.js:753)
at fn (index.js:122)
at Object.eval (emotion-react.browser.esm.js:10)
at eval (emotion-react.browser.esm.js:362)
at Object.../node_modules/@emotion/react/dist/emotion-react.browser.esm.js (index.js:956)
at __webpack_require__ (index.js:753)
at fn (index.js:122)
(truncated)
经过进一步检查,问题似乎是解决 react 'createContext' 函数的问题。
var EmotionCacheContext = /* #__PURE__ */Object(react__WEBPACK_IMPORTED_MODULE_0__["createContext"])( // we're doing this to avoid preconstruct's dead code elimination in this one case
组件库使用 react v16.8.1,UI 库使用相同版本。
任何想法或指示将不胜感激!
解决方案
我遇到了同样的问题,对我有用的是删除我的锁定文件和节点模块,然后运行yarn
或npm install
. 之后,我在浏览器中做了一个空缓存并硬重新加载。我也跑了gatsby clean
,因为我正在使用 Gatsby。我不确定哪一步成功了,但这对我有帮助!根据您的问题,我猜您正在迁移到 Chakra UI v1?如果是这种情况,请确保您在此处关注他们的迁移文档。
推荐阅读
- r - 如何摆脱 R 中具有相同名称的多个列?
- r - 生成一个 for 循环,该循环将制作绘图并为它们提供正确的标题
- pandas - 时间序列指数 Pandas 系列 - 如何屏蔽范围
- reactjs - 提交表单后如何在 React.js 中更新 DOM
- java - 如何从 MySQL 将确切的行数加载到 jTable 并对剩余的行进行分页?
- python - 简单的 SFTP 脚本
- javascript - PHP动态列表检索返回未定义索引
- scala - Lisp 宏和 scala 宏有什么区别?
- ruby-on-rails - 如何在 ActiveRecord 中的客户表中获取最受欢迎的邮政编码?
- perl - 为什么在生成守护进程时会剥离 utf8 IO 层?