【问题标题】:error TS2305: Module '"react"' has no exported member 'Node'错误 TS2305:模块 '"react"' 没有导出的成员 'Node'
【发布时间】:2022-01-16 16:57:12
【问题描述】:

我将 React Native 项目与官方文档一起运行,并将 TypeScript 添加到项目中。 我在执行 'yarn tsc' 时出现了很多 ESlint 错误,例如:

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

10 import type {Node} from 'react';

我知道这只是一个TS错误,但我很困惑,为什么代码'import type {Node} from 'react';'会产生这个错误

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"
  ]
}

【问题讨论】:

    标签: reactjs typescript react-native


    【解决方案1】:

    尝试添加tsconfig.json

    "skipLibCheck": true,

    【讨论】:

      【解决方案2】:

      因为 React 不导出名为 Node 的类型。也许您正在寻找ReactNode

      TS Playground link

      import type {Node} from 'react'; // error
      import type {ReactNode} from 'react'; // ok
      

      【讨论】:

        猜你喜欢
        • 2017-03-29
        • 2022-01-18
        • 2021-12-20
        • 2021-03-25
        • 2020-11-13
        • 2018-09-04
        • 2017-06-13
        • 2019-11-28
        • 2019-02-02
        相关资源
        最近更新 更多