ReactNative运行错误:无法克隆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)
我真的很感激反馈,我被困在这一点上。