react-native - TypeError:TypeError:未定义不是一个对象(评估'_this._setComponentRef.bind')
问题描述
每次尝试运行该项目时,我都会收到此错误。我尝试了许多其他解决方案/修复,但没有成功。
这太奇怪了,因为我没有更新/安装项目的任何新依赖项。我唯一记得的是昨天重新启动了我的机器,然后发生了这种情况。我觉得这与babel有关。
我上次处理它时,没有出现错误。但是当我试图从上周中断的地方继续时,它只是显示这个红色屏幕。我已经重置缓存,再次删除 node_modules 和 npm install,重新启动我的笔记本电脑。但仍然有同样的错误。
TypeError: TypeError: undefined is not an object (evaluating '_this._setComponentRef.bind')
This error is located at:
in AnimatedComponent (at TouchableOpacity.js:256)
in TouchableOpacity (at LogIn.js:236)
in RCTView (at View.js:44)
in RCTView (at View.js:44)
in RCTView (at View.js:44)
in RCTScrollView (at ScrollView.js:977)
in ScrollView (at LogIn.js:126)
in LoginScreen (created by inject-LoginScreen-with-userProfile)
in inject-LoginScreen-with-userProfile (created by SceneView)
in SceneView (created by SwitchView)
in SwitchView (created by Navigator)
in Navigator (at createAppContainer.js:388)
in NavigationContainer (at Authentication.js:22)
in Authentication (at Router/index.js:41)
in Routes (created by inject-Routes-with-userProfile)
in inject-Routes-with-userProfile (at App.js:72)
in Provider (at App.js:71)
in App (at registerRootComponent.js:17)
in RootErrorBoundary (at registerRootComponent.js:16)
in ExpoRootComponent (at renderApplication.js:34)
in RCTView (at View.js:44)
in RCTView (at View.js:44)
in AppContainer (at renderApplication.js:33)
应用程序.json:
{
"name": "flo",
"main": "node_modules/expo/AppEntry.js",
"private": true,
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"eject": "expo eject"
},
"dependencies": {
"@babel/plugin-proposal-decorators": "^7.3.0",
"@mindinventory/react-native-tab-bar-interaction":"github:mindinventory/react-native-tab-bar-interaction",
"axios": "^0.18.0",
"expo": "^31.0.6",
"firebase": "^5.8.5",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-31.0.0.tar.gz",
"react-native-actionsheet": "^2.4.2",
"react-native-app-intro-slider": "^1.0.1",
"react-native-carousel-control": "^2.0.1",
"react-native-dash": "0.0.9",
"react-native-easy-grid": "^0.2.1",
"react-native-firebase": "^5.2.3",
"react-native-google-places-autocomplete": "^1.3.9",
"react-native-modal-datetime-picker": "^6.0.0",
"react-native-motion": "^0.2.0",
"react-native-router-flux": "^4.0.5",
"react-native-sideswipe": "^1.4.2",
"react-native-snap-carousel": "^3.7.5",
"react-navigation": "^3.3.2",
"react-navigation-redux-helpers": "^3.0.0",
"react-redux": "^6.0.1",
"redux": "^4.0.1",
"redux-axios-middleware": "^4.0.0"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.3.4",
"babel-preset-expo": "^5.0.0",
"jest-expo": "^32.0.0",
"mobx": "^5.9.0",
"mobx-react": "^5.4.3",
"mobx-state-tree": "^3.10.2",
"schedule": "^0.4.0"
} }
babel.config
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
plugins: [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose": true }]
]
};
};
知道如何让它再次运行吗?为什么会这样?
解决方案
请尝试将@babel/transform-flow-strip-types
插件添加到您的 babel 配置中。流条类型插件必须在类属性之前。如果你不这样做,将会有一个测试用例失败。
"plugins": [
[
"@babel/plugin-transform-flow-strip-types"
],
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
]
]
推荐阅读
- android - 如何将 Retrofit 对象直接注入到存储库类中?
- excel - 带变量的公式 IF
- java - 如何解决这个 Treeset 程序?
- unicode - 如何在 Windows 上使用笔记本电脑键盘打字?
- ruby-on-rails - #update 的 RSPEC 测试无法更新某些参数
- mysql - 两个表之间的条件语句
- android - Android - 这不能改变 ActionBar 中搜索图标的颜色吗?
- sql - 如何在 Sqlserver 中加入 3 个表
- node.js - 如何在一行 shell 命令中运行几个 npm 脚本?
- python - 在画布上定位标签