简体   繁体   English

如何在Codesandbox中使用Babel插件提案抛出表达式?

[英]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.

相关问题 使用 Firebase 在 CodeSandbox 上找不到/安装 babel 插件“proposal-decorators” - Could not find/install babel plugin 'proposal-decorators' on CodeSandbox with Firebase 如何使用 vite 启用“@babel/plugin-proposal-decorators” - How do i enable "@babel/plugin-proposal-decorators" with vite 如何在Babel中使用类似函数的导入建议功能? - How to use function-like import proposal feature in Babel? Babel插件 - 提议装饰器未按预期工作 - Babel plugin-proposal-decorators not working as expected 如何使用Babel 7的插件提议装饰器和异步函数来装饰异步方法? - How do I decorate an async method using Babel 7's plugin-proposal-decorators with an async function? 如何让 @babel/plugin-proposal-private-methods 在 vue.js webpack 模板中工作? - How to make @babel/plugin-proposal-private-methods work in the vue.js webpack template? @ babel / plugin-proposal-class-properties不起作用 - @babel/plugin-proposal-class-properties doesn't work 带有 Babel 的 ESLint:在 .eslintrc 中未找到声明的 plugin-proposal-class-properties - ESLint with Babel: plugin-proposal-class-properties not found declared in .eslintrc 带有 Babel plugin-proposal-export-default-from 的 ESLint - ESLint with Babel plugin-proposal-export-default-from 错误:找不到模块“@babel/plugin-proposal-class-properties” - Error: Cannot find module '@babel/plugin-proposal-class-properties'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM