解析导入模块react-native中的错误

Uke*_*ken 8 importerror eslint react-native eslintrc

我和一个朋友正在开发一个小型反应原生应用程序。他最近将 Es-lint 和 prettier 添加到了项目中,但我遇到了一个导入错误,此后一直无法解决。

从反应本机的任何导入都会显示以下错误

模块“C:/Users/Brendan/projects/garden-manager-native/node_modules/@types/react-native/index”导入模块'react-native'中的解析错误:';' 预期的。(14:32)eslintimport/命名空间。

我在 package.json 中有以下依赖项:

  "dependencies": {
    "@expo/vector-icons": "^13.0.0",
    "@react-native-async-storage/async-storage": "~1.15.0",
    "@react-navigation/bottom-tabs": "^6.0.5",
    "@react-navigation/native": "^6.0.2",
    "@react-navigation/native-stack": "^6.1.0",
    "@reduxjs/toolkit": "^1.8.0",
    "date-fns": "^2.28.0",
    "expo": "~44.0.0",
    "expo-asset": "~8.4.6",
    "expo-camera": "~12.1.2",
    "expo-cli": "^5.3.0",
    "expo-constants": "~13.0.1",
    "expo-file-system": "~13.1.4",
    "expo-font": "~10.0.4",
    "expo-linking": "~3.0.0",
    "expo-splash-screen": "~0.14.1",
    "expo-status-bar": "~1.2.0",
    "expo-updates": "~0.11.7",
    "expo-web-browser": "~10.1.0",
    "normalizr": "^3.6.2",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "react-hook-form": "^7.28.1",
    "react-native": "0.64.3",
    "react-native-calendars": "^1.1283.0",
    "react-native-elements": "^3.4.2",
    "react-native-safe-area-context": "^3.3.2",
    "react-native-screens": "~3.10.1",
    "react-native-timeline-flatlist": "^0.8.0",
    "react-native-vector-icons": "^9.1.0",
    "react-native-web": "0.17.1",
    "react-redux": "^7.2.6",
    "redux-persist": "^6.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@testing-library/jest-native": "4.0.4",
    "@testing-library/react-native": "^9.1.0",
    "@trivago/prettier-plugin-sort-imports": "^3.3.0",
    "@types/jest": "^27.4.1",
    "@types/react": "~17.0.21",
    "@types/react-native": "~0.64.12",
    "eslint": "^8.21.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-config-universe": "^11.1.0",
    "jest": "^26.6.3",
    "jest-expo": "~44.0.0",
    "prettier": "^2.7.1",
    "react-test-renderer": "17.0.1",
    "typescript": "~4.3.5"
  },
  "private": true,
  "resolutions": {
    "@types/react": "17.0.2",
    "@types/react-dom": "17.0.2",
    "react-devtools-core": "4.14.0"
  }
Run Code Online (Sandbox Code Playgroud)

我的朋友没有收到此错误。

我似乎无法找到有关此特定问题的太多信息,但我尝试重新安装 node_modules 文件夹,但没有任何效果。

我知道我可以禁用此规则来消除错误,但更愿意找到更好的解决方案。

小智 12

您可以关注此线程:https ://github.com/facebook/react-native/issues/28549

或临时使用:

settings: {
  'import/ignore': ['react-native'],
}
Run Code Online (Sandbox Code Playgroud)

在你的eslintrc文件中


blu*_*yd8 7

根据会议https://github.com/facebook/react-native/issues/28549#issuecomment-657249702

您应该使用此模式,因为它不会匹配诸如react-native-navigation.

  settings: {
    'import/ignore': ['node_modules/react-native/index\\.js$']
  }
Run Code Online (Sandbox Code Playgroud)