📌  相关文章
📜  模块 '".. .. .. node_modules react-native"' 没有导出的成员 'View' - Javascript (1)

📅  最后修改于: 2023-12-03 15:26:50.581000             🧑  作者: Mango

如何解决“模块 '...node_modules react-native' 没有导出的成员 'View'”错误

当在使用 React Native 进行开发时,你可能会遇到 “模块 '...node_modules react-native' 没有导出的成员 'View'” 错误。这是因为你的代码中有使用到 View 组件,但是在引入 React Native 库时没有正确指定 View 组件的路径。

这个问题可以通过以下步骤来解决:

  1. 检查你的代码中是否有使用到 View 组件,如果没有使用到,那么可能是某个组件在内部使用了 View 组件。

  2. 确认你的 React Native 版本是否正确。View 组件从 React Native 0.50 版本开始成为内置组件。

  3. 在你的代码文件开头,添加以下代码:

import { View } from 'react-native';

这样就可以正确地导入 View 组件,避免出现上述错误。

  1. 如果你使用的是 TypeScript,在你的 tsconfig.json 文件中添加以下代码:
"paths": {
  "react-native": [
    "./node_modules/react-native"
  ],
  "*": [
    "./node_modules/@types/*"
  ]
}

这样就可以正确地解析 TypeScript 中的 React Native 模块。

总之,解决 “模块 '...node_modules react-native' 没有导出的成员 'View'” 错误的关键在于正确的导入 View 组件。如果你遵循以上步骤,应该可以成功解决这个问题。