我正在构建一个 React-Native android 应用程序。我想将 App.js 文件移动到 src 文件夹中以获得更清晰的文件结构,因此我将此行添加到 expo 对象内的 app.json 文件中:
{
"expo": {
"entryPoint": "./src/App.js",
当我运行该应用程序时,我得到了相同的旧默认 expo 应用程序。我在文件中有什么并不重要。当我更改任何内容时,它会抛出此错误:
Unable to resolve "../../App" from "node_modules/expo/AppEntry.js"
我还尝试按照建议将这一行添加到文件中 here :
export default Expo.registerRootComponent(App);
我正在使用 Linux 和 android studio 模拟器。
最佳答案
每当我尝试这个时,对我有用的是导入 registerRootComponent
并按以下方式使用它:
这是一个非常简单的App.js
import React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { registerRootComponent } from 'expo'; // import it explicitly
class App extends React.Component {
render () {
return (
<View style={styles.container}>
<Text>Hello</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white'
}
});
export default registerRootComponent(App); // this is how I register the App component
这是我的app.json
{
"expo": {
"entryPoint": "./src/App.js", <---- notice my entry point
"name": "ExpoTester",
"slug": "ExpoTester",
"privacy": "public",
"sdkVersion": "32.0.0",
"platforms": [
"ios",
"android"
],
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
}
}
}
这是我的package.json
{
"name": "NewApp",
"version": "0.0.0",
"description": "No description",
"author": null,
"private": true,
"main": "node_modules/expo/AppEntry.js",
"dependencies": {
"expo": "^32.0.0",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz"
}
}
这是我的文件结构:
├── app.json
├── assets
│ ├── icon.png
│ └── splash.png
├── package-lock.json
├── package.json
└── src
└── App.js <- notice the App.js is no longer in the root directory it is now in src
此外,在对应用程序的结构进行任何重大更改时,我喜欢关闭 bundler ,然后使用 expo start -c
重新启动它以确保清除缓存。
关于android - 在 app.json 中定义 expo entryPoint 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54886508/