RN - 找不到模块供应商/反应本机矢量图标的声明文件



我正在使用expo 34.0.1进行反应原生开发。我正在为该项目使用 TypeScript,并在带有玩笑的测试脚本中运行tsc --project . --noEmit。这会导致以下错误:

node_modules/@expo/vector-icons/build/createIconSet.d.ts:2:55 - error TS7016:找不到模块的声明文件 './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' 隐式具有"任何"类型。

2 导出 { DEFAULT_ICON_COLOR, DEFAULT_ICON_SIZE } 从 './vendor/react-native-vector-icons/lib/create-icon-set'; 发现 1 个错误。

npm 错误! 代码生命周期 npm 错误! errno 1 npm 错误!@ tsc-test:tsc --project . --noEmitnpm 错误!退出状态 1 npm 错误! 呵呵!在 @ tsc 测试脚本中失败。呵呵!这可能不是问题 新人。上面可能有其他日志记录输出。

呵呵!可以在以下位置找到此运行的完整日志:npm ERR!
/用户/.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"]
}

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

有什么想法可以解决这个问题吗?

第 1 步:

在 package.json 的 "scripts" 对象中,只需添加:

"postinstall": "npx typesync"

第 2 步:

运行yarnnpm install以有效地运行"安装后"脚本。 添加所有缺少的包后,您将获得要添加到项目中的所有新类型的列表

它可能看起来像这样:

📦 yourAppNameHere — package.json (4 new typings added, 0 unused typings removed)
├─ + @types/babel__core
├─ + @types/react-native-vector-icons
├─ + @types/react

第 3 步:

您可能会被要求再次运行npm installyarn,这将安装添加的软件包,您将很高兴!

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

"noImplicitAny": false,

这将消除您的错误。eslint 将捕获代码中的任何隐式内容。

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

最新更新