You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native新手疑问:Expo项目为何未生成index.js文件?

Hey there! Great question—this is a super common point of confusion when switching between bare React Native projects and Expo managed workflows, so let’s break this down clearly.

Why you don’t see index.js in Expo managed projects

When you use react-native init to create a bare React Native project, the index.js file is a critical entry point: it connects your JavaScript code to the native Android/iOS containers via AppRegistry.registerComponent().

Expo managed projects work differently—they abstract away most of the native boilerplate for you. Instead of requiring you to manually register your root component, Expo handles this low-level setup under the hood. By default, Expo uses App.js as your root component (you can confirm this in your project’s app.json or expo.json file, where the entryPoint is implicitly set to ./App.js). That’s why you don’t see an index.js file—Expo doesn’t need you to write that registration code yourself.

How to handle entry points in Expo projects

You have two straightforward options based on your needs:

  • Stick with the default setup: If you don’t need special global initialization logic (like setting up state management, loading custom fonts, or handling deep links upfront), just use App.js as your starting point. All your app’s core logic can live here, just like you’d use index.js in a bare project.

  • Create a custom entry file (if needed): If you do need to add global setup steps before rendering your app, you can define a custom entry point:

    1. Create a new file (e.g., src/index.js or index.js in your project root)
    2. Add code to register your root component using Expo’s registerRootComponent (this is Expo’s optimized replacement for bare React Native’s AppRegistry):
      import { registerRootComponent } from 'expo';
      import App from './App';
      
      // Add your global initialization code here (e.g., load fonts, initialize analytics)
      // ...
      
      registerRootComponent(App);
      
    3. Update your app.json (or expo.json) to point to this new entry file:
      {
        "expo": {
          "entryPoint": "./src/index.js"
        }
      }
      

A quick tip: Expo’s managed workflow is built to minimize boilerplate, so only create a custom entry file if you truly need it—most of the time, App.js will serve you perfectly.

内容的提问来源于stack exchange,提问作者Murad Zulfugarov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:28:05