首页 > 解决方案 > 模块 AppRegistry 未为 Expo 注册可调用模块(调用 runApplication)

问题描述

我正在尝试使用 expo 编写一个 react-native 应用程序,并且我开始将其启动代码用于具有多个选项卡的应用程序。然后我创建了一个 LoginScreen.js 文件,如下所示:

import React, { Component } from 'react';
import { AppRegistry, TextInput, Button } from 'react-native';

export default class Login extends React.Component {
  constructor(props) {
    super(props);
    this.state = { username: '', passwd: '', };
  }

  render() {
    return (
    <React.Fragment>
          <TextInput>
            style={{height: 40, borderColor: 'gray', borderWidth: 1}}
            onChangeText={(username) => this.setState({username})}
            value={this.state.username}
          </TextInput>
          <TextInput>
            style={{height: 40, borderColor: 'gray', borderWidth: 1}}
            onChangeText={(passwd) => this.setState({passwd})}
            value={this.state.passwd}
          </TextInput>
          <Button>
            onPress={this.verifyLogin}
            title = "Login"
          </Button>
      </React.Fragment>
    );

  }
    verifyLogin() {
        if (this.state.username == 'test' && this.state.passwd == 'test'){
            this.setState( () => ({username: 'login succeeded!'}));
        }
    }

}

我想将此用作用户看到的第一页,而不是默认的 HomeScreen.js。我试图通过将以下行添加到我的 app.json 文件来做到这一点:

"entryPoint": "screens/LoginScreen.js"

但是,当我尝试此操作时,我收到以下错误消息:Module AppRegistry is not registered callable module (calling runApplication)我已经找到了关于同一错误消息的另外两个 stackoverflow 问题(Module AppRegistry is not registered callable module (calling runApplication)React-Native: Module AppRegistry is not a registered callable module ),并且我已经尝试过第一个中的解决方案(例如重新启动npm,添加该行

AppRegistry.registerComponent("Login", () => Login))

这给了我以下错误消息:应用程序主尚未注册)。另外,我引用的两个stackoverflow页面没有使用expo,而是直接使用react-native,这意味着它们引用的一些文件对我来说并不存在(例如index.ios.js文件)。此外,我尝试将 HomeScreen.js 文件的全部内容复制并粘贴到 Login.js 文件中,它仍然给了我同样的错误,让我相信我需要设置一些其他设置,但是我不知道是什么。摆脱此错误或以其他方式使首页成为登录页面的任何帮助都会有所帮助。

标签: javascriptreact-nativeexpo

解决方案


推荐阅读