一、问题:

新建一个工程后,在执行react-native start 后访问:http://localhost:8081/index.android.bundle?platform=android

报错:

Error: Unable to resolve module `./index.android` from `D:\DevelopTools\ReactNativeProjects\FirstProject/.`: The module `./index.android` could not be found from `D:\DevelopTools\ReactNativeProjects\FirstProject/.`. Indeed, none of these files exist:
  * `D:\DevelopTools\ReactNativeProjects\FirstProject\index.android(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)`
  * `D:\DevelopTools\ReactNativeProjects\FirstProject\index.android\index(.native||.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)`
    at ModuleResolver.resolveDependency (D:\DevelopTools\ReactNativeProjects\FirstProject\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:163:15)
    at ResolutionRequest.resolveDependency (D:\DevelopTools\ReactNativeProjects\FirstProject\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (D:\DevelopTools\ReactNativeProjects\FirstProject\node_modules\metro\src\node-haste\DependencyGraph.js:283:16)
    at D:\DevelopTools\ReactNativeProjects\FirstProject\node_modules\metro\src\lib\transformHelpers.js:264:42
    at Server.<anonymous> (D:\DevelopTools\ReactNativeProjects\FirstProject\node_modules\metro\src\Server.js:1049:41)
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (D:\DevelopTools\ReactNativeProjects\FirstProject\node_modules\metro\src\Server.js:99:24)
    at _next (D:\DevelopTools\ReactNativeProjects\FirstProject\node_modules\metro\src\Server.js:119:9)

 

 

二、解决:

是react native版本更新的一些变动。原来工程中会创建:index.ios.js 和index.android.js,现在只会创建index.js。一个简单的规避方法,就是copy 一份index.js 文件命名为index.android.js即可

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐