[英]How to use Babel Plugin Proposal Throw Expressions in Codesandbox?
Using React in Codesandbox i tried to throw new Error('Something went wrong'); 我在Codesandbox中使用React试图抛出新的错误(“出了点问题”); and i had this error: 我有这个错误:
I already added this dependency: https://babeljs.io/docs/en/babel-plugin-proposal-throw-expressions and still won't work. 我已经添加了此依赖项: https : //babeljs.io/docs/en/babel-plugin-proposal-throw-expressions仍然无法正常工作。
Here's my code 这是我的代码
<div className="App">
<ErrorBoundary>
<h1>Counter {counter >= 10 ? throw new Error("Over 10!") : null}</h1>
</ErrorBoundary>
</div>
After adding a dependency in your sandbox you must enable it. 在沙箱中添加依赖项后,必须启用它。 To add a Babel dependency add a .babelrc
config file. 要添加Babel依赖项,请添加.babelrc
配置文件。 Then add the plugin name into the plugins array. 然后将插件名称添加到plugins数组中。
{
"plugins": [
"transform-runtime",
"proposal-optional-chaining",
"proposal-throw-expressions"
],
}
The configuration files can be added from the config button on the left side. 可以从左侧的config按钮添加配置文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.