ermish
ermish

Reputation: 1270

Typescript + Parcel new JSX transform - React is not defined error

I've updated to React 17+ and am now getting a React is not defined issue when removing import React from 'react' statements from typescript TSX and JSX files.

How can I fix this?

Upvotes: 3

Views: 1631

Answers (1)

ermish
ermish

Reputation: 1270

I've identified the problem is the version of a few babel plugins that are outdated that Parcel (version 2.0.0-beta.3.1 at time of writing) is using.

Here's my solution:

Add these two packages to you package.json file:

yarn add --dev @babel/core @babel/plugin-transform-react-jsx
or
npm i -D @babel/core @babel/plugin-transform-react-jsx

update your babel config or create a new .babelrc file:

{
  "plugins": [
    [
      "@babel/plugin-transform-react-jsx",
      {
        "runtime": "automatic"
      }
    ]
  ]
}

Upvotes: 6

Related Questions