Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolving this error: 'React' must be in scope when using JSX

Tags:

reactjs

eslint

I am using React18.2.0 and I have the error shown below when running my project

React must be in scope error

I have seen some solutions which suggest if I am using Eslint (which I am), I should disable react scope in the rules. I have as shown in my Eslint config file below but it is not working.

Eslint config file showing react scope off

Another solution was to add import React from "react"; This works, however, from the documentation we do not need to include this anymore from React17 upwards. So I do not know why I still have this error.

Any assistance would be appreciated

This is my package.json file

package.json file

like image 579
David.E Avatar asked Jul 21 '26 09:07

David.E


1 Answers

You have to add the 'jsx-runtime' to your ESLint config file – for the new flat structure, your eslint.config.js file should be configured as follows:

// Other imports
pluginReact from "eslint-plugin-react";

export default [

  // (...)

  pluginReact.configs.flat['jsx-runtime'],

  // (...)

];
like image 115
Consta Gorgan Avatar answered Jul 23 '26 01:07

Consta Gorgan