gpt4 book ai didi

javascript - 没有正文无法转换节点

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:53:32 26 4
gpt4 key购买 nike

我正在尝试运行 the examplereact-testing-library 中测试 react Hook 。但它似乎在这条线上失败了:

testHook(() => ({count, increment} = useCounter({ initialCount: 2 })))

看起来和Babel有关。尝试谷歌搜索但找不到任何似乎有同样问题的人。我用 create-react-app 安装了 webpack。

这是堆栈跟踪:

 ● Test suite failed to run

Can't convert node without a body

at NodePath.ensureBlock (node_modules/@babel/traverse/lib/path/conversion.js:64:11)
at Scope.push (node_modules/@babel/traverse/lib/scope/index.js:727:12)
at Object.toSequenceExpression (node_modules/@babel/types/lib/converters/toSequenceExpression.js:19:11)
at NodePath.replaceExpressionWithStatements (node_modules/@babel/traverse/lib/path/replacement.js:203:36)
at NodePath.insertAfter (node_modules/@babel/traverse/lib/path/modification.js:128:17)
at NodePath.replaceWithMultiple (node_modules/@babel/traverse/lib/path/replacement.js:85:22)
at PluginPass.AssignmentExpression (node_modules/babel-preset-react-app/node_modules/@babel/plugin-transform-destructuring/lib/index.js:433:14)
at newFn (node_modules/@babel/traverse/lib/visitors.js:193:21)
at NodePath._call (node_modules/@babel/traverse/lib/path/context.js:53:20)
at NodePath.call (node_modules/@babel/traverse/lib/path/context.js:40:17)

最佳答案

我不确定如何解决 Babel 问题,但如果你写:

testHook(() => { return ({count, increment} = useCounter({ initialCount: 2 }))})

代替:

testHook(() => ({count, increment} = useCounter({ initialCount: 2 })))

它有效。可能他们正在使用一些您当前设置没有的高级 ES6 语法糖。希望对您有所帮助!

关于javascript - 没有正文无法转换节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54620790/

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