无法读取未定义的React Native的属性'style'

时间:2017-05-29 08:55:38

标签: react-native

我从package.json文件中删除了一些未使用的依赖项,然后我执行了rm -rf node_modules,然后npm install

如果我现在在Xcode中构建我的项目我没有任何错误,但是如果我尝试在模拟器中运行它,我会得到如下红屏:

enter image description here

在模拟器中我得到:

TypeError: Cannot read property 'Symbol(Symbol.iterator)' of null
    at launchEditor (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/react-native/local-cli/server/util/launchEditor.js:153:29)
    at Object.handle (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/react-native/local-cli/server/middleware/openStackFrameInEditorMiddleware.js:17:7)
    at next (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/connect/lib/proto.js:174:15)
    at Object.handle (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/react-native/local-cli/server/middleware/getDevToolsMiddleware.js:74:7)
    at next (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/connect/lib/proto.js:174:15)
    at Object.handle (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/react-native/local-cli/server/middleware/getDevToolsMiddleware.js:74:7)
    at next (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/connect/lib/proto.js:174:15)
    at Object.compression [as handle] (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/compression/index.js:205:5)
    at next (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/connect/lib/proto.js:174:15)
    at IncomingMessage.<anonymous> (/Users/boris/Projects/autralis-seller/AutralisSeller/node_modules/react-native/local-cli/server/middleware/loadRawBodyMiddleware.js:20:5)

我不知道发生了什么。知道怎么解决吗?

修改

Scene.js来自react-native router-flux navigation:

/**
 * Copyright (c) 2015-present, Pavel Aksonov
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree.
 *
 */
import React, { PropTypes } from 'react';
import { ViewPropTypes, Text } from 'react-native';

export default class extends React.Component {

  // @todo - should all props be documented/specified here?

  static propTypes = {
    tabBarStyle: ViewPropTypes.style,
    tabBarSelectedItemStyle: ViewPropTypes.style,
    tabBarIconContainerStyle: ViewPropTypes.style,
    tabBarShadowStyle: ViewPropTypes.style,
    tabSceneStyle: ViewPropTypes.style,
    tabStyle: ViewPropTypes.style,
    tabTitleStyle: Text.propTypes.style,
    tabSelectedTitleStyle: Text.propTypes.style,
    tabTitle: PropTypes.string,
  };

  render() {
    return null;
  }
}

1 个答案:

答案 0 :(得分:2)

所以我也有这个问题,你的帖子帮我解决了。 React Native Router Flux大约在2周前更新,其中View.propTypes已弃用于新的ViewPropTypes。这是对它的承诺。 https://github.com/aksonov/react-native-router-flux/commit/36dc20418987850677c52905beda59310a0500c3

问题是当这个更新提交到实时分支时,库版本没有从3.37.0增加,所以如果你在实现提交后完成了npm安装,你的软件包将使用新的更改进行更新,但是你很可能不会更清楚他们所做的事情(除非你阅读了你在项目中使用的每个包的提交更新)

我发现将react-native-router-flux恢复到早期版本修复了这个问题。我使用了3.36.0

npm install react-native-router-flux@3.36.0 --save