gpt4 book ai didi

javascript - es错误类如何避免栈溢出

转载 作者:行者123 更新时间:2023-11-30 20:13:35 25 4
gpt4 key购买 nike

我创建了一个自定义错误类,在我更改 babel 配置之前它工作正常,现在抛出堆栈溢出错误。

这是错误类(为了重现而精简):

export default class UserError extends Error {
constructor(code, message, innerError, hint) {
super();
}
}

这是我的 .babelrc 文件(我使用的是 babel 7):

{
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": [
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-proposal-logical-assignment-operators",
["@babel/plugin-proposal-optional-chaining", { "loose": false }],
["@babel/plugin-proposal-pipeline-operator", { "proposal": "minimal" }],
["@babel/plugin-proposal-nullish-coalescing-operator", { "loose": false }],
"@babel/plugin-proposal-do-expressions",

["@babel/plugin-proposal-decorators", { "legacy": true }],
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions",

"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
["@babel/plugin-proposal-class-properties", { "loose": false }],
"@babel/plugin-proposal-json-strings"
]
}

这是我得到的错误:

  RangeError: Maximum call stack size exceeded
at UserError.Wrapper (/Volumes/Development/Development/Xolvio/xspecs/modules/utilities/error.js:18:461)
at new UserError (/Volumes/Development/Development/Xolvio/xspecs/modules/utilities/error.js:2:48)
at construct (/Volumes/Development/Development/Xolvio/xspecs/node_modules/harmony-reflect/reflect.js:2086:12)
at UserError.Wrapper (/Volumes/Development/Development/Xolvio/xspecs/modules/utilities/error.js:18:473)
at new UserError (/Volumes/Development/Development/Xolvio/xspecs/modules/utilities/error.js:2:48)
at construct (/Volumes/Development/Development/Xolvio/xspecs/node_modules/harmony-reflect/reflect.js:2086:12)
at UserError.Wrapper (/Volumes/Development/Development/Xolvio/xspecs/modules/utilities/error.js:18:473)
at new UserError (/Volumes/Development/Development/Xolvio/xspecs/modules/utilities/error.js:2:48)
at construct (/Volumes/Development/Development/Xolvio/xspecs/node_modules/harmony-reflect/reflect.js:2086:12)
at UserError.Wrapper (/Volumes/Development/Development/Xolvio/xspecs/modules/utilities/error.js:18:473)
at new UserError (/Volumes/Development/Development/Xolvio/xspecs/modules/utilities/error.js:2:48)
at construct (/Volumes/Development/Development/Xolvio/xspecs/node_modules/harmony-reflect/reflect.js:2086:12)
at UserError.Wrapper (/Volumes/Development/Development/Xolvio/xspecs/modules/utilities/error.js:18:473)
at new UserError (/Volumes/Development/Development/Xolvio/xspecs/modules/utilities/error.js:2:48)
at construct (/Volumes/Development/Development/Xolvio/xspecs/node_modules/harmony-reflect/reflect.js:2086:12)
at UserError.Wrapper (/Volumes/Development/Development/Xolvio/xspecs/modules/utilities/error.js:18:473)

知道是什么原因导致溢出以及如何解决它吗?

最佳答案

这是 harmony-reflect 库中的错误,它显示在您的堆栈跟踪中。它似乎用损坏的函数替换了现有的 Reflect.construct 函数。我已将其归档在 https://github.com/tvcutsem/harmony-reflect/issues/81 中.

您需要找出加载该库的内容并查看是否可以将其删除。不幸的是,它似乎正在创建一个不符合规范并破坏 Babel 输出代码的 Reflect.construct 函数。

关于javascript - es错误类如何避免栈溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52152988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com