react-native - React Native 运行错误:无法克隆 XXX
问题描述
我不知道如何更好地描述它。我正在研究 react-native 项目,发生了一些事情,由于某种原因我不能再运行它了。我收到一些奇怪的消息,例如无法克隆某些功能。
error: src/requests/TimeoutRequest.ts: function (path) {
return fn.call(state, path, state);
} could not be cloned.
或者:
error: src/sensors/GPS.ts: Program(path) {
importAll = path.scope.generateUid("$$_IMPORT_ALL");
importDefault = path.scope.gen...<omitted>... } could not be cloned.
所有版本:
npm version: 7.10.0
"react": "^16.11.0",
"react-native": "^0.62.2",
dev:
"@babel/core": "^7.13.15",
"@babel/runtime": "^7.13.10",
"babel-jest": "^24.9.0",
"babel-plugin-root-import": "^6.6.0",
"metro-react-native-babel-preset": "^0.57.0",
"react-test-renderer": "16.9.0"
如果我注释掉这个函数。我在另一个中遇到错误,依此类推。中间发生了什么:我更新了 npm 版本。然后我在下载一些库时遇到了一些问题,我不得不rm -rf node_modules && npm install
.
我尝试了什么:
谷歌搜索,一般。找不到任何可行的解决方案。发现它可能是 babel 问题,但它可能完全错误,我不知道
npm start --reset-cache
删除缓存文件夹,守望者的东西,等等
npm install --legacy-peer-deps
克隆项目并在另一个文件夹中执行所有操作
恢复或删除 package-lock.json 和 yarn.lock。安装有或没有它们
尝试更新 babel 版本
以相同的结果运行 android 和 ios
运行调试或发布版本,构建发布也失败并出现相同的错误。
没有什么帮助。
令人惊讶的是,以前一切正常,它所涉及的这些功能都包含在以前的版本中,没有任何问题。可能有些库版本搞砸了。我有它们,但之后rm -rf node_modules
我没有了。可能是babel问题。但我真的不知道,我读过它。
以防万一,例如“无法克隆”的功能。我什至不在那里克隆对象。
export async function TimeoutRequest(
req: any,
timeout: number = 5000,
): Promise<Response> {
const timeoutId = setTimeout(() => controller.abort(), timeout)
const controller = new AbortController()
req.signal = controller.signal
return new Promise((resolve, reject) => {
fetch(req)
.then(res => {
clearTimeout(timeoutId)
resolve(res)
})
.catch(err => {
clearTimeout(timeoutId)
reject(err)
})
})
}
此外,在发生错误时添加了堆栈跟踪:
at Object.serialize (v8.js:267:7)
at _default (node_modules/@babel/core/lib/transformation/util/clone-deep.js:16:30)
at normalizeFile (node_modules/@babel/core/lib/transformation/normalize-file.js:52:36)
at normalizeFile.next (<anonymous>)
at run (node_modules/@babel/core/lib/transformation/index.js:31:50)
at run.next (<anonymous>)
at node_modules/@babel/core/lib/transform-ast.js:20:41
at Generator.next (<anonymous>)
at evaluateSync (node_modules/gensync/index.js:251:28)
我非常感谢您的反馈,我被困在这一点上。
解决方案
我发现这很可能是 babel 问题。如果您像我一样遇到这个问题,升级库,只需回滚到可以工作的旧版本,然后逐个升级库。我升级后重现了这个问题@babel/core
。我只是再次回滚,再也没有碰过巴别塔。仍然可以正常工作。
推荐阅读
- javascript - 如何在 vue js 中打印 HTML、CSS 代码而不将它们呈现为 HTML 元素和 CSS 属性?
- java - 通过Java中的restTemplate从rest webservice获取垃圾值
- jquery - HTTP404:未找到 - 服务器未找到与请求的 URI(统一资源标识符)匹配的任何内容,其中我的页面有一个母版页
- android - 为什么我不能调用片段视图的 onClick 属性
- php - Laravel - Laratrust - 重命名权限名称
- cursive - 草书在注释行中向前/向后导航单词
- php - 找不到类 Google_Client()
- haskell - 以下类型的 Functor 实例是什么: newtype F2 xa = F2 ((a -> x) -> a)
- php - 当用户点击它时,有什么方法可以通过锚标签传递 SESSION id?
- mysql - 错误号: 3780 外键约束 '%s' 中引用列 '%s' 和引用列 '%s' 不兼容