12

I ran the React Native project along with the official documentation and added TypeScript to the project. Many ESlint errors occurred when I was executing 'yarn tsc', for example:

App.tsx:10:14 - error TS2305: Module '"react"' has no exported member 'Node'.

10 import type {Node} from 'react';

I know this is just an TS error, but I am confused, why does the code, 'import type {Node} from 'react';', produce this error

tsconfig.json:

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "isolatedModules": true,
    "jsx": "react-native",
    "lib": ["es2017"],
    "moduleResolution": "node",
    "noEmit": true,
    "strict": true,
    "target": "esnext"
  },
  "exclude": [
    "node_modules",
    "babel.config.js",
    "metro.config.js",
    "jest.config.js"
  ]
}
Sen
  • 121
  • 1
  • 4

3 Answers3

12

Because React doesn't export a type named Node. Maybe you are looking for ReactNode?

TS Playground link

import type {Node} from 'react'; // error
import type {ReactNode} from 'react'; // ok
jsejcksn
  • 27,667
  • 4
  • 38
  • 62
2

try to add in tsconfig.json

"skipLibCheck": true,

Or Azoulay
  • 179
  • 2
0

Starting a new standard project gives you an App.js with these lines:

import type {Node} from 'react';
    
const App: () => Node = () => {

And the code works even if you remove the import.

I've checked the TS template created by:

npx react-native init AwesomeTSProject --template react-native-template-typescript

It gives you an App.tsx with only

const App = () => {

I'm not digging the reason around the missing return type in TS, that is in fact a React.ReactNode

Davide Pedron
  • 697
  • 1
  • 8
  • 17