Jim*_*Jim 6 react-native react-navigation
尝试在 android 上使用 react-navigation 构建 react-native v0.61.5 应用程序时遇到此错误。iOS 运行良好,不知道为什么我会收到这个 index.android 文件错误,因为我认为 react-native 合并的索引文件只是index.js
作为入口点的单数。
这是完整的错误:
加载依赖图,完成。错误:无法
./index.android
从``解析模块 :16) 在 /Users/name/Desktop/Development/app/node_modules/metro/src/lib/transformHelpers.js:267:42 在服务器。(/Users/name/Desktop/Development/app/node_modules/metro/src/Server.js:1088:41) at Generator.next () at asyncGeneratorStep (/Users/name/Desktop/Development/app/node_modules/metro/ src/Server.js:99:24) 在 _next (/Users/name/Desktop/Development/app/node_modules/metro/src/Server.js:119:9)
这是 index.js:
import { AppRegistry } from 'react-native';
import App from './App';
import 'react-native-gesture-handler';
import { name as appName } from './app.json';
AppRegistry.registerComponent(appName, () => App);
Run Code Online (Sandbox Code Playgroud)
包.json:
{
"name": "appName",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint ."
},
"dependencies": {
"algoliasearch": "^4.0.3",
"moment": "^2.24.0",
"moment-timezone": "^0.5.27",
"react": "16.9.0",
"react-instantsearch-native": "^6.3.0",
"react-native": "0.61.5",
"react-native-agora": "^2.9.1-alpha.2",
"react-native-algolia-dropdown": "^1.6.0",
"react-native-calendars": "^1.220.0",
"react-native-chart-kit": "^4.3.0",
"react-native-code-push": "^6.0.0",
"react-native-extended-stylesheet": "^0.12.0",
"react-native-firebase": "^5.6.0",
"react-native-gesture-handler": "^1.5.2",
"react-native-image-crop-picker": "^0.26.1",
"react-native-material-dropdown": "^0.11.1",
"react-native-reanimated": "^1.4.0",
"react-native-safe-area-context": "^0.6.2",
"react-native-screens": "^1.0.0-alpha.23",
"react-native-snap-carousel": "^3.8.4",
"react-native-splash-screen": "^3.2.0",
"react-native-svg": "^9.13.6",
"react-native-view-shot": "^3.1.2",
"react-navigation": "^4.0.10",
"react-navigation-drawer": "^2.3.3",
"react-navigation-stack": "^1.10.3",
"react-redux": "^7.1.3",
"redux": "^4.0.4",
"redux-persist": "^6.0.0",
"redux-thunk": "^2.3.0",
"rn-fetch-blob": "^0.11.2",
"tipsi-stripe": "^7.5.1"
},
"devDependencies": {
"@babel/core": "7.7.5",
"@babel/runtime": "7.7.6",
"@react-native-community/eslint-config": "0.0.5",
"babel-jest": "24.9.0",
"eslint": "6.7.2",
"jest": "24.9.0",
"metro-react-native-babel-preset": "0.56.3",
"react-test-renderer": "16.9.0"
},
"jest": {
"preset": "react-native"
}
}
Run Code Online (Sandbox Code Playgroud)
图书馆已正确集成,有什么建议吗?
如果您的项目中有 index.ios,它会抛出错误,因为它无法在您的项目根目录中找到 index.android 文件
您可以创建 index.android.js 文件并在该文件中导入原始 index.js 文件并检查它是否有效(快速修复)
所以基本上在 React v0.49 之后,你不需要 index.ios.js 和 index.android.js。你只需要 index.js:
但是出现这个问题有两种情况
第一种情况的解决方案
//For android in this directory you need to make this change android/app/src/main/java/<yourPackage>/MainApplication.java
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
//...
@Override
protected String getJSMainModuleName() {
return "index";
}
};
Run Code Online (Sandbox Code Playgroud)
//对于这个目录中的ios ios//AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
//...
}
Run Code Online (Sandbox Code Playgroud)
这两种解决方案在某些情况下也有效
或者
在某些情况下,很难确定为什么有人会遇到此问题。
归档时间: |
|
查看次数: |
4166 次 |
最近记录: |