每个模块只允许一个默认导出”,但只显示一个

时间:2018-08-14 02:42:44

标签: javascript reactjs react-native react-navigation

我有一个根目录“ App.js”,并且只包含一个“导出默认值”。以前运行良好(主要只是使用React Navigation的应用程序的路由功能)。但是我需要查看选项卡的焦点,以便尝试实现此库:https://github.com/pmachowski/react-navigation-is-focused-hoc

现在,当我加载应用程序时,它会给我这个错误:

  

'无法加载192.168 .....,错误:../../src/App.js:只有一个   每个模块允许默认导出'

但是我相信我只有一个。这是App.js:

import React from 'react';
import { createBottomTabNavigator,createStackNavigator } from 'react-navigation';
import { updateFocus, getCurrentRouteKey } from 'react-navigation-is-focused-hoc'

import SearchTab from './components/Tabs/SearchTab';
import HomeTab from './components/Tabs/HomeTab';
import ScannerTab from './components/Tabs/ScannerTab';
import SettingsTab from './components/Tabs/SettingsTab';
import Ionicons from 'react-native-vector-icons/Ionicons';
import StockModal from './components/Modals/StockModal';

const MainStack = createBottomTabNavigator(
    {
        Home: HomeTab,
        Search: SearchTab,
        Scanner: ScannerTab,
        Settings: SettingsTab,
        //Todo: Total overlay modals HERE
    },
    {
        navigationOptions: ({ navigation }) => ({
            tabBarIcon: ({ focused, tintColor }) => {
                const { routeName } = navigation.state;
                let iconName;

                if (routeName === 'Home') {
                    iconName = `ios-information-circle${focused ? '' : '-outline'}`;
                } else if (routeName === 'Settings') {
                    iconName = `ios-options${focused ? '' : '-outline'}`;
                }else if (routeName === 'Scanner') {
                    iconName = `ios-barcode${focused ? '' : '-outline'}`;
                }else if (routeName === 'Search') {
                    iconName = `ios-search${focused ? '' : '-outline'}`;
                }
                return <Ionicons name={iconName} size={25} color={tintColor} />;
            },
        }),
        tabBarOptions: {
            activeTintColor: 'tomato',
            inactiveTintColor: 'gray',
        },
    }
);


DefaultStack = createStackNavigator(
    {
        Main: {
            screen: MainStack,
        },
        QuickStockScreen: {
            screen: StockModal,
        },
    },
    {
        mode: 'modal',
        headerMode: 'none',
    }
);

export default class App extends React.Component {

    render() {
        return (
            <DefaultStack
                onNavigationStateChange={(prevState, currentState) => {
                    // If you want to ignore the state changed from `DrawerNavigator`, use this:
                    /*
                      if (/^Drawer(Open|Close|Toggle)$/.test(getCurrentRouteKey(currentState)) === false) {
                        updateFocus(currentState)
                        return
                      }
                    */
                    updateFocus(currentState)
                }}
            />
        )
    }
}

也;解决此问题的另一种方法是在React Navigation中的选项卡被聚焦时,另一个更“最新”的库或接收道具或状态的方法;从their own issue thread起,该方法都是混乱且不清楚的。

Failed to load bundle(http://192.168.0.10:8081/index.bundle?platform=ios&dev=true&minify=false) with error:(SyntaxError: /Users/kenji/StockManager/src/App.js: Only one default export allowed per module. (73:0)

[0m [90m 71 | [39m}[0m
[0m [90m 72 | [39m[0m
[0m[31m[1m>[22m[39m[90m 73 | [39m[36mexport[39m [36mdefault[39m [33mRootStack[39m [33m=[39m createStackNavigator([0m
[0m [90m    | [39m[31m[1m^[22m[39m[0m
[0m [90m 74 | [39m    {[0m
[0m [90m 75 | [39m        [33mMain[39m[33m:[39m {[0m
[0m [90m 76 | [39m            screen[33m:[39m [33mMainStack[39m[33m,[39m[0m (null))

__38-[RCTCxxBridge loadSource:onProgress:]_block_invoke.248
    RCTCxxBridge.mm:422
___ZL36attemptAsynchronousLoadOfBundleAtURLP5NSURLU13block_pointerFvP18RCTLoadingProgressEU13block_pointerFvP7NSErrorP9RCTSourceE_block_invoke.118
__80-[RCTMultipartDataTask URLSession:streamTask:didBecomeInputStream:outputStream:]_block_invoke
-[RCTMultipartStreamReader emitChunk:headers:callback:done:]
-[RCTMultipartStreamReader readAllPartsWithCompletionCallback:progressCallback:]
-[RCTMultipartDataTask URLSession:streamTask:didBecomeInputStream:outputStream:]
<redacted>
<redacted>
<redacted>
<redacted>
_dispatch_client_callout
_dispatch_block_invoke_direct
_dispatch_client_callout
_dispatch_block_invoke_direct
dispatch_block_perform
<redacted>
_dispatch_client_callout
_dispatch_continuation_pop
_dispatch_async_redirect_invoke
_dispatch_root_queue_drain
_dispatch_worker_thread3
_pthread_wqthread
start_wqthread

1 个答案:

答案 0 :(得分:0)

因此,我怀疑这是文件权限或类似问题的双重问题。 我正在运行hackintosh以使用xcode开发iOS,并进行了真实设备测试和引导,这很奇怪。例如加载关闭时被置于“暂停”状态的内容有时无法正确执行。

是这种情况,在适当的强制重启后,它已修复。 当我将更改还原到App.js之后,我意识到这是一个问题,并且仍然显示完全相同的问题。