在react-native 0.49更新之后,Object不是构造函数

时间:2017-11-17 21:32:35

标签: javascript react-native

更新本机反应后从0.45.x到0.50.3(并将index.ios.js重命名为index.js,如图所示)我在index.js(之前的index.ios.js)中收到此错误: “对象不是构造函数(评估'new _app2.default()')”

这是我的index.js文件

import { AppRegistry } from 'react-native';
import App from './app/';

const app = new App();

AppRegistry.registerComponent('airand', () => app);

这是我的app / index.js文件:

import { Platform, Linking } from 'react-native'
import { Provider } from "react-redux"
import allReducers from "./reducers"
import { Navigation } from 'react-native-navigation'
import RCTSFSafariViewController from 'react-native-sfsafariviewcontroller'
import FontAwesome from 'react-native-vector-icons/FontAwesome'

import registerScreens from './screens/'
import Token from './services/token'
import Api from './services/api'
import configureStore from './store/configureStore'
// import { login, logout } from './reducers/app-root/actions'
import defaultFitlerData from './constants/nearby-cte.js'

const store = configureStore();

registerScreens(store, Provider);

export default class App {

    constructor() {
        this._populateTabBarIcons().then(() => {
            this._startApp();
            this._checkUserLoggedIn();
            store.subscribe(() => this._actionListener());
        });
        // handle linking
        Linking.getInitialURL().then((url) => {
            if (url) {
                this._handleOpenURL(url);
            }
        }).catch((e) => {})
        Linking.addEventListener('url', (event) => this._handleOpenURL(event.url));
    };
    _populateTabBarIcons () {
        return new Promise((resolve, reject) => {
            Promise.all([
                    FontAwesome.getImageSource('map-marker', 30),
                    FontAwesome.getImageSource('map-marker', 30),
                    FontAwesome.getImageSource('ellipsis-h', 30),
                    FontAwesome.getImageSource('ellipsis-h', 30),
                    FontAwesome.getImageSource('plus-square-o', 30),
                    FontAwesome.getImageSource('plus-square', 30),
                    FontAwesome.getImageSource('comment-o', 30),
                    FontAwesome.getImageSource('comment', 30),
                    FontAwesome.getImageSource('user-o', 30),
                    FontAwesome.getImageSource('user', 30)
            ]).then((values) => {
                this.tabBarIcons = [];
                this.selectedTabBarIcons = [];
                for (var i = 0; i < values.length; i += 2) {
                    this.tabBarIcons.push(values[i]);
                    this.selectedTabBarIcons.push(values[i+1]);
                }
                resolve(true);
            }).catch((error) => {
                reject(error);
            }).done();
        });
    };
    componentWillUnmount() {
        // TODO: find a way to call this
        Linking.removeEventListener('url', (event) => this._handleOpenURL(event.url));
    };
    _getParameterByName(name, url) {
        name = name.replace(/[\[\]]/g, "\\$&");
        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
        return decodeURIComponent(results[2].replace(/\+/g, " "));
    };
    async _handleOpenURL(url) {
        const pathName = url.split('://')[1].split('?')[0];
        if (pathName.indexOf('login_successful') != -1) {
            const code = this._getParameterByName('code', url);
            if (code) {
                let response = await Api.getTokenFromCode(code);
                if (response.status == 200) {
                    this._checkUserLoggedIn();
                }
            }
        }
        RCTSFSafariViewController.close();
    };
    async _checkUserLoggedIn() {
        let isValid = await Token.isValidRefreshToken();
        if (isValid) {
          this._startApp('logged-in')
        } else {
          this._startApp('logged-out')
        }
    };
    _actionListener() {
        let currentRoot = store.getState().appRoot.root;
        if (currentRoot != lastRoot)
        this._startApp(currentRoot);
    };
    _getTabs() {
        const tabLabel = ['Nearby', 'Pending', 'New', 'Chat', 'Profile'];
        const screens = [
            'airand.NearbyServices',
            'airand.PendingServicesScreen',
            'airand.NewServiceScreen',
            'airand.ChatScreen',
            'airand.Profile'
        ];
        var tabs = [];
        for (var i = 0; i < screens.length; i++) {
            tabs.push({
                icon: this.tabBarIcons[i],
                selectedIcon: this.selectedTabBarIcons[i],
                screen: screens[i]
            });
        };
        return tabs;
    };
    async _startApp(root = null) {
      lastRoot = root
        switch(root) {
            case 'logged-in':
                self.logged_in = true
                Navigation.startTabBasedApp({
                    tabs: this._getTabs(),
                    animationType: 'slide-down',
                    title: 'Redux Example',
                    tabsStyle: {
                        tabBarButtonColor: '#979797',
                        tabBarSelectedButtonColor: '#f79100',
                    }
                });
                return
            case 'logged-out':
                Navigation.startSingleScreenApp({
                    screen: { screen: 'airand.LoginScreen' }
                });
                return
            default:
                Navigation.startSingleScreenApp({
                    screen: { screen: 'airand.LoadingScreen' }
                });
                return
        }
    };
}

这似乎是一个愚蠢的错误,但我花了好几个小时,所以请任何帮助将不胜感激,我已经尝试评论一些东西几乎所有app / index.js但没有运气。

谢谢!

1 个答案:

答案 0 :(得分:0)

我认为你的问题是这个......

> kubectl get svc
NAME                    TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)
api                     LoadBalancer   10.3.240.197   123.123.123.123  443:32126/TCP
nginx-default-backend   ClusterIP      10.3.253.16    <none>           80/TCP
nginx-ingress-lb        LoadBalancer   10.3.245.191   234.234.234.234  443:31051/TCP
website                 ClusterIP      10.3.254.180   <none>           80/TCP

> kubectl get ingress
NAME          HOSTS             ADDRESS           PORTS
ingress       site.domain.com   234.234.234.234   80, 443

> host api.domain.com
api.domain.com has address 123.123.123.123
> host site.domain.com
site.domain.com has address 234.234.234.234

它告诉你const app = new App(); 不是构造函数。

尝试将App()更改为此...

{root}/index.js