react-native - RN - 找不到模块供应商/react-native-vector-icons 的声明文件

标签 react-native expo

我正在使用 expo 34.0.1 进行 native 开发。我正在为项目使用 TypeScript 并运行 tsc --project 。 --noEmit 在测试脚本中开玩笑。这会导致以下错误:

node_modules/@expo/vector-icons/build/createIconSet.d.ts:2:55 - error TS7016: Could not find a declaration file for module './vendor/react-native-vector-icons/lib/create-icon-set'. '../node_modules/@expo/vector-icons/build/vendor/react-native-vector-icons/lib/create-icon-set.js' implicitly has an 'any' type.

2 export { DEFAULT_ICON_COLOR, DEFAULT_ICON_SIZE } from './vendor/react-native-vector-icons/lib/create-icon-set'; Found 1 error.

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! @ tsc-test: tsc --project . --noEmit npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the @ tsc-test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR!
/Users/.npm/_logs/2019-08-31T19_25_49_598Z-debug.log

tsconfig.json:

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "module": "es6",
    "target": "es6",
    "lib": ["es2016", "esnext.asynciterable"],
    "jsx": "react-native",
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "types": ["jest"],
    "moduleResolution": "node",
    "allowJs": false,
    "esModuleInterop": true
  },
  "exclude": ["node_modules"]
}

package.json

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "test": "npm run tslint && npm run tsc-test && npm run jest",
    "tslint": "tslint --project .",
    "tsc-test": "tsc --project . --noEmit",
    "jest": "jest"
  },
  "dependencies": {
    "@types/enzyme": "^3.10.3",
    "expo": "^34.0.1",
    "moment": "^2.24.0",
    "react": "16.9.0",
    "react-dom": "^16.9.0",
    "react-moment": "^0.9.2",
    "react-native": "https://github.com/expo/react-native/archive/sdk-34.0.0.tar.gz",
    "react-native-elements": "^1.1.0",
    "react-native-gesture-handler": "~1.3.0",
    "react-native-reanimated": "~1.1.0",
    "react-native-vector-icons": "^6.6.0",
    "react-native-web": "^0.11.4",
    "react-navigation": "^3.12.1"
  },
  "devDependencies": {
    "@types/expo": "^32.0.13",
    "@types/jest": "^24.0.18",
    "@types/react": "^16.9.2",
    "@types/react-test-renderer": "^16.9.0",
    "enzyme": "^3.10.0",
    "enzyme-adapter-react-16": "^1.14.0",
    "jest": "^24.9.0",
    "jest-expo": "^34.0.1",
    "react-test-renderer": "^16.9.0",
    "ts-jest": "^24.0.2",
    "tslint": "^5.19.0",
    "tslint-config-airbnb": "^5.11.1",
    "typescript": "^3.5.3"
  },
  "private": true,
  "jest": {
    "preset": "jest-expo",
    "transform": {
      "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js",
      "^.+\\.tsx?$": "ts-jest"
    },
    "testMatch": [
      "**/__tests__/**/*.ts?(x)",
      "**/?(*.)+(spec|test).ts?(x)"
    ],
    "moduleFileExtensions": [
      "js",
      "ts",
      "tsx"
    ],
    "globals": {
      "ts-jest": {
        "tsConfig": {
          "jsx": "react"
        }
      }
    },
    "setupFilesAfterEnv": [
      "./src/setupTests.js"
    ]
  }
}

有什么办法解决这个问题吗?

最佳答案

我可以看到你正在使用 eslint。因此,编辑编译器选项并添加是安全的

"noImplicitAny": false,

这将使您的错误消失。并且 eslint 会在你的代码中捕捉到任何隐含的 any。

根据我的理解,我希望这是正确的:-)

关于react-native - RN - 找不到模块供应商/react-native-vector-icons 的声明文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57741074/

相关文章:

android - 从冷启动(当应用程序被杀死时)使用 Expo 读取推送通知

react-native - 将 Amplitude Analytics 集成到 React Native App 与 Expo

javascript - 类型错误 : undefined is not an object (evaluating 'item.phoneNumbers[0]' )

php - 使用 PHP 进行博览会推送通知

android - 找到路径为 'lib/arm64-v8a/libnode.so' 的 2 个文件 - nodejs-mobile-react-native 的 jniLibs 问题

react-native - react 原生抽屉切换不起作用

javascript - 项目在平面列表中不可见

react-native - 尝试将 expo 安装为 "npm install expo-cli --global"但出现许多错误

android - 如何在react-native应用程序中打开网站(Android和iOS)

android - 如何访问相机 - React Native