0

Using React in Codesandbox i tried to throw new Error('Something went wrong'); and i had this error:

enter image description here

I already added this dependency: https://babeljs.io/docs/en/babel-plugin-proposal-throw-expressions and still won't work.

Here's my code

<div className="App">
  <ErrorBoundary>
    <h1>Counter {counter >= 10 ? throw new Error("Over 10!") : null}</h1>
  </ErrorBoundary>
</div>
Twirlman
  • 1,109
  • 2
  • 12
  • 30

1 Answers1

1

After adding a dependency in your sandbox you must enable it. To add a Babel dependency add a .babelrc config file. Then add the plugin name into the plugins array.

{
  "plugins": [
    "transform-runtime",
    "proposal-optional-chaining",
    "proposal-throw-expressions"
  ],
}

enter image description here

The configuration files can be added from the config button on the left side.

AV Paul
  • 2,299
  • 1
  • 9
  • 11