React Native - TypeError:无法读取未定义的属性“干净”
Posted
技术标签:
【中文标题】React Native - TypeError:无法读取未定义的属性“干净”【英文标题】:React Native - TypeError: Cannot read property 'clean' of undefined 【发布时间】:2020-10-11 23:11:41 【问题描述】:React Native v 0.62.2。
npm run android
给我以下错误:
TypeError: 无法读取未定义的“干净”属性
ExceptionsManager.js:76 Invariant Violation:Module AppRegistry 不是注册的可调用模块(调用runApplication)
package.json
"name": "client",
"version": "0.0.1",
"private": true,
"scripts":
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"postinstall": "rn-nodeify --install process,buffer,crypto,stream,assert,events,vm --hack",
"graphql:codegen": "apollo client:codegen --target typescript"
,
"dependencies":
"@react-native-community/art": "^1.2.0",
"@react-native-community/async-storage": "^1.10.3",
"@react-native-community/cameraroll": "^1.7.1",
"@react-native-community/clipboard": "^1.2.2",
"@react-native-community/geolocation": "^2.0.2",
"@react-native-community/masked-view": "^0.1.10",
"@react-native-community/push-notification-ios": "^1.2.0",
"@skele/components": "^1.0.0-alpha.40",
"apollo-cache-inmemory": "^1.6.6",
"apollo-client": "^2.6.10",
"apollo-link-context": "^1.0.20",
"apollo-link-error": "^1.1.13",
"apollo-link-http": "^1.5.17",
"apollo-link-ws": "^1.0.20",
"apollo-upload-client": "^13.0.0",
"assert": "^1.5.0",
"base-64": "^0.1.0",
"buffer": "^4.9.2",
"ethereumjs-abi": "^0.6.8",
"ethereumjs-util": "^6.2.0",
"ethereumjs-wallet": "^0.6.3",
"events": "^1.1.1",
"firebase": "^7.15.1",
"graphql": "^14.6.0",
"graphql-tag": "^2.10.3",
"i18n-js": "^3.5.1",
"invert-color": "^2.0.0",
"lodash.memoize": "^4.1.2",
"moment": "^2.26.0",
"process": "^0.11.10",
"react": "^16.13.1",
"react-apollo": "^3.1.5",
"react-dom": "^16.11.1",
"react-native": "^0.62.2",
"react-native-actionsheet": "^2.4.2",
"react-native-app-intro-slider": "^4.0.2",
"react-native-button": "^3.0.1",
"react-native-camera": "^3.28.0",
"react-native-crypto": "^2.2.0",
"react-native-dark-mode": "^0.2.2",
"react-native-device-info": "^5.5.7",
"react-native-dialog-input": "^1.0.7",
"react-native-elements": "^2.0.0",
"react-native-fast-image": "^8.1.5",
"react-native-firebase": "^5.6.0",
"react-native-geocoding": "^0.4.0",
"react-native-gesture-handler": "^1.6.1",
"react-native-google-places-autocomplete": "^1.7.1",
"react-native-image-crop-picker": "^0.25.3",
"react-native-image-filter-kit": "^0.7.1",
"react-native-image-picker": "^2.3.1",
"react-native-image-progress": "^1.1.1",
"react-native-image-view": "^2.1.9",
"react-native-indicators": "^0.17.0",
"react-native-ionicons": "^4.6.5",
"react-native-keyboard-aware-scroll-view": "^0.9.1",
"react-native-keyboard-aware-view": "^0.0.14",
"react-native-localize": "^1.4.0",
"react-native-maps": "^0.27.1",
"react-native-modal": "^11.5.6",
"react-native-modalbox": "^2.0.0",
"react-native-progress": "^4.1.2",
"react-native-push-notification": "^3.5.2",
"react-native-randombytes": "^3.5.3",
"react-native-reanimated": "~1.9.0",
"react-native-safe-area-context": "^3.0.2",
"react-native-safe-area-view": "^1.1.1",
"react-native-screens": "^2.8.0",
"react-native-search-box": "^0.0.19",
"react-native-splash-screen": "^3.2.0",
"react-native-swiper": "^1.6.0",
"react-native-vector-icons": "^6.6.0",
"react-native-video": "^4.4.5",
"react-native-view-more-text": "^2.1.0",
"react-native-web": "~0.12.2",
"react-navigation": "^4.1.0",
"react-navigation-drawer": "^2.4.11",
"react-navigation-hooks": "^1.1.0",
"react-navigation-stack": "^2.1.0",
"react-navigation-tabs": "^2.7.0",
"react-redux": "^7.2.0",
"readable-stream": "^1.0.33",
"redux": "^4.0.5",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"remote-redux-devtools": "^0.5.16",
"rn-nodeify": "^10.2.0",
"stream-browserify": "^1.0.0",
"subscriptions-transport-ws": "^0.9.16",
"uuidv4": "^6.0.7",
"vm-browserify": "0.0.4"
,
"devDependencies":
"@babel/core": "^7.6.2",
"@babel/runtime": "^7.6.2",
"@react-native-community/eslint-config": "^0.0.5",
"@types/apollo-upload-client": "^8.1.3",
"@types/jest": "^24.0.24",
"@types/react-native": "^0.60.25",
"@types/react-native-push-notification": "^3.0.9",
"@types/react-test-renderer": "16.9.1",
"@typescript-eslint/eslint-plugin": "^2.12.0",
"@typescript-eslint/parser": "^2.12.0",
"apollo": "^2.27.4",
"babel-jest": "^25.1.0",
"babel-plugin-transform-remove-console": "^6.9.4",
"eslint": "^6.5.1",
"jest": "^25.1.0",
"jetifier": "^1.6.6",
"metro": "^0.59.0",
"metro-react-native-babel-preset": "^0.56.0",
"react-test-renderer": "16.9.0",
"typescript": "^3.8.3"
,
"jest":
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
,
"react-native":
"_stream_transform": "readable-stream/transform",
"_stream_readable": "readable-stream/readable",
"_stream_writable": "readable-stream/writable",
"_stream_duplex": "readable-stream/duplex",
"_stream_passthrough": "readable-stream/passthrough",
"stream": "stream-browserify",
"crypto": "react-native-crypto",
"vm": "vm-browserify"
,
"browser":
"_stream_transform": "readable-stream/transform",
"_stream_readable": "readable-stream/readable",
"_stream_writable": "readable-stream/writable",
"_stream_duplex": "readable-stream/duplex",
"_stream_passthrough": "readable-stream/passthrough",
"stream": "stream-browserify",
"crypto": "react-native-crypto",
"vm": "vm-browserify"
,
"resolutions":
"@react-native-community/cli-debugger-ui": "4.7.0"
android/bundle.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript
ext
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
supportLibVersion = "28.0.0"
supportVersion = "28.0.0"
googlePlayServicesVersion = "15.0.1"
facebookSdkVersion = "4.37.0"
repositories
google()
jcenter()
mavenCentral()
dependencies
classpath("com.android.tools.build:gradle:3.5.2")
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
allprojects
repositories
mavenLocal()
maven
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
maven
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
maven url 'https://maven.google.com'
maven url "https://www.jitpack.io"
google()
jcenter()
android/app/bundle.gradle
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js",
enableHermes: false, // clean and rebuild if changing
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
android
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileOptions
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
dexOptions
javaMaxHeapSize "3g"
defaultConfig
applicationId "com.client"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.12"
missingDimensionStrategy 'react-native-camera', 'general'
multiDexEnabled true
splits
abi
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
signingConfigs
debug
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
release
if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE'))
storeFile file(MYAPP_UPLOAD_STORE_FILE)
storePassword MYAPP_UPLOAD_STORE_PASSWORD
keyAlias MYAPP_UPLOAD_KEY_ALIAS
keyPassword MYAPP_UPLOAD_KEY_PASSWORD
buildTypes
debug
signingConfig signingConfigs.debug
release
// Caution! In production, you need to generate your own keystore file.
// see https://facebook.github.io/react-native/docs/signed-apk-android.
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
packagingOptions
pickFirst "lib/armeabi-v7a/libc++_shared.so"
pickFirst "lib/arm64-v8a/libc++_shared.so"
pickFirst "lib/x86/libc++_shared.so"
pickFirst "lib/x86_64/libc++_shared.so"
// applicationVariants are e.g. debug, release
applicationVariants.all variant ->
variant.outputs.each output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
dependencies
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:+" // From node_modules
implementation 'androidx.appcompat:appcompat:1.2.0-rc01'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
implementation 'com.android.support:multidex:1.0.3'
implementation 'androidx.multidex:multidex:2.0.1'
implementation "com.google.android.gms:play-services-base:17.0.0"
implementation "com.google.firebase:firebase-core:17.0.1"
implementation "com.google.firebase:firebase-auth:17.0.0"
implementation "com.google.firebase:firebase-firestore:19.0.0"
implementation "com.google.firebase:firebase-messaging:19.0.0"
implementation "com.google.firebase:firebase-storage:17.0.0"
debugImplementation("com.facebook.flipper:flipper:$FLIPPER_VERSION")
exclude group:'com.facebook.fbjni'
debugImplementation("com.facebook.flipper:flipper-network-plugin:$FLIPPER_VERSION")
exclude group:'com.facebook.flipper'
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:$FLIPPER_VERSION")
exclude group:'com.facebook.flipper'
if (enableHermes)
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
else
implementation jscFlavor
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy)
from configurations.compile
into 'libs'
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply plugin: 'com.google.gms.google-services'
【问题讨论】:
附加发生错误的JS文件 @AkilaDevinda 它在ExceptionsManger.js
,我想它的通用错误处理类
是的,但错误是未定义的变量名。我认为它来自您的第一个 Loading JS 文件。检查名称为 'clean' 的代码。它没有定义。还要确保卸载应用程序并重建
@AkilaDevinda 感谢您为我指明正确的方向
欢迎您,很高兴它有帮助:)
【参考方案1】:
正如@AkilaDevinda 建议的那样,我在代码中寻找clean
,发现我正在使用库中的cleanExtractedImagesCache()
函数
react-native-image-filter-kit
.
问题是我在 react-native.config.js
module.exports =
dependencies:
'react-native-image-filter-kit':
platforms:
android: null, // disable Android platform, other platforms will still autolink if provided
,
,
因此,在 android cleanExtractedImagesCache()
中找不到并导致未定义的错误。谢谢。
【讨论】:
很高兴它有帮助:)以上是关于React Native - TypeError:无法读取未定义的属性“干净”的主要内容,如果未能解决你的问题,请参考以下文章
react-native-web 更新:TypeError:无法读取未定义的属性“样式”
React-Native - TypeError:未定义不是评估useContext的对象
@react-native-firebase/messaging : TypeError: (0 , _messaging.default)(...).registerForRemoteNotific
在 React Native 中使用 useContext 的上下文 API 显示 TypeError