'React' refers to a UMD global, but the current file is a module
Solution 1:
Create React App supports the new JSX transformation out of the box in version 4 but if you are using a custom setup, the following is needed to remove the TypeScript error when writing jsx
without import React from 'react'
:
-
typescript
version of at least version 4.1 -
react
andreact-dom
of at least version 17 -
tsconfig.json
must have ajsx
compilerOption ofreact-jsx
orreact-jsxdev
example:
// tsconfig.json
{
"compilerOptions": {
...
"jsx": "react-jsx"
...
},
}
TypeScript documentation for its support of React 17 JSX Factories can be found here
Solution 2:
This error message comes from TypeScript compiler. The React 17 new jsx transform is not currently supported in Typescript 4.0, and will be supported in 4.1.
TypeScript v4.1 Beta - React 17 JSX Factories
Solution 3:
Adding
import React from 'react'
fixes this issue