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.
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.
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.jsas your starting point. All your app’s core logic can live here, just like you’d useindex.jsin 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:
- Create a new file (e.g.,
src/index.jsorindex.jsin your project root) - Add code to register your root component using Expo’s
registerRootComponent(this is Expo’s optimized replacement for bare React Native’sAppRegistry):import { registerRootComponent } from 'expo'; import App from './App'; // Add your global initialization code here (e.g., load fonts, initialize analytics) // ... registerRootComponent(App); - Update your
app.json(orexpo.json) to point to this new entry file:{ "expo": { "entryPoint": "./src/index.js" } }
- Create a new file (e.g.,
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

