0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

expoでApp.jsが読まれず、expoの初期画面が表示されるときの解決策

0
Posted at

症状

Expoをインストール後、App.jsを新たに作って起動すると、Expoのインストール直後の初期画面が表示され、自分で書いたApp.jsの画面が表示されない事象がありました

App.jsでconsoleや意図的にエラーを表示されるようにaaaとか書いても初期画面のままだったので、App.jsが読まれていないと推察しました

app.jsonのpluginsを"plugins": []にしても解決せず

/プロジェクトルート
├── App.js
├── .expo
├── src
│   
├── firebaseConfig.js
├── app.config.js
├── package.json
App.js
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { AuthProvider, useAuth } from './src/contexts/AuthContext';
import HomeScreen from './src/screens/HomeScreen';
import LoginScreen from './src/screens/LoginScreen';
import SignUpScreen from './src/screens/SignUpScreen';

const Stack = createNativeStackNavigator();

function AppStack() {
  const { user, loading } = useAuth();
  console.log('Auth status:', { user, loading });//ログ
  if (loading) return null; 
  aaa //エラーを起こさせるための文字列
  return (
    <NavigationContainer>
      <Stack.Navigator>
        {user ? (
          <Stack.Screen name="Home" component={HomeScreen} />
        ) : (
          <>
            <Stack.Screen name="Login" component={LoginScreen} />
            <Stack.Screen name="SignUp" component={SignUpScreen} />
          </>
        )}
      </Stack.Navigator>
    </NavigationContainer>
  );
}

export default function App() {
  return (
    <AuthProvider>
      <AppStack />
    </AuthProvider>
  );
}
package.json
{
  "name": "hoge",
  "main": "expo-router/entry",
  "version": "1.0.0",
  以下略
}
app.json
{
  "expo": {
    "name": "hoge",
    "slug": "hoge",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/images/icon.png",
    "scheme": "hoge",
    "userInterfaceStyle": "automatic",
    "newArchEnabled": true,
    "ios": {
      "supportsTablet": true
    },
    "android": {
      "package": "com.hoge.app",
      "adaptiveIcon": {
        "foregroundImage": "./assets/images/adaptive-icon.png",
        "backgroundColor": "#ffffff"
      },
      "edgeToEdgeEnabled": true
    },
    "web": {
      "bundler": "metro",
      "output": "static",
      "favicon": "./assets/images/favicon.png"
    },
    "plugins": [
      "expo-router",
      [
        "expo-splash-screen",
        {
          "image": "./assets/images/splash-icon.png",
          "imageWidth": 200,
          "resizeMode": "contain",
          "backgroundColor": "#ffffff"
        }
      ]
    ],
    "experiments": {
      "typedRoutes": true
    }
  }
}

解決方法

package.jsonのmainのところを以下にしたら、読み込まれるようになりました!
package.json
{
  "name": "hoge",
  "main": "node_modules/expo/AppEntry.js",
  "version": "1.0.0",
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?