在app.json中定义Expo入口点不起作用



我正在构建一个反应的android应用。我想将app.js文件移动到一个清洁文件结构中的src文件夹中,因此我将此行添加到了expo对象中的app.json文件:

{
  "expo": {
    "entryPoint": "./src/App.js",

运行应用程序时,我会获得相同的旧默认博览会应用程序。我在文件中有什么都没关系。当我更改任何内容时,它会引发此错误:

Unable to resolve "../../App" from "node_modules/expo/AppEntry.js"

我还尝试在此处建议将此行添加到文件中:

export default Expo.registerRootComponent(App);

我正在使用Linux和Android Studio Simulator。

每当我尝试过此操作时,对我有用的是导入 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重新启动它,以确保清洁缓存。

,对于那些遇到此错误的人:

[Unhandled promise rejection: Error: Unable to activate keep awake]

我找到了一种基于此的新方法来实现重组以及上面的安德鲁提供的答案。

这是我的结构:

.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)

相关内容

  • 没有找到相关文章

最新更新