我正在构建一个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模拟器。
答案 0 :(得分:0)
每当我尝试过这种方法时,对我有用的就是导入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
此外,在对应用程序的结构进行重大更改时,我想关闭捆绑器,然后使用expo start -c
重新启动捆绑器,以确保清除了缓存。
答案 1 :(得分:0)
好吧,对于那些遇到此错误的人:
[Unhandled promise rejection: Error: Unable to activate keep awake]
。
我发现了一种基于 this 和上面 Andrew 提供的 answer 实现重组的新方法。
这是我的结构:
.expo
|- many_files
.expo-shared
|- many_files
assests
|- many_files
node_modules
src
|- App.tsx
app.json
package.json
... (many more)
这是我的package.json
:
{
"main": "./src/App.tsx",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"expo": "~41.0.1",
"expo-status-bar": "~1.0.4",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz",
"react-native-web": "~0.13.12"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@types/react": "~16.9.35",
"@types/react-native": "~0.63.2",
"typescript": "~4.0.0"
},
"private": true
}
我的app.json
:
{
"expo": {
"entryPoint": "./src/App.tsx",
"name": "front",
"slug": "front",
"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
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
}
},
"web": {
"favicon": "./assets/favicon.png"
}
}
}
最后,我的App.tsx
:
import React from 'react'
import { StyleSheet, Text, View } from 'react-native'
import { StatusBar } from 'expo-status-bar'
import { registerRootComponent } from 'expo'
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center'
}
})
const App = () => {
return (
<View style={styles.container}>
<Text>Open up App.tsx to start working on your app!</Text>
<StatusBar style='auto' />
</View>
)
}
export default registerRootComponent(App)