无法使用Expo解决React Native App中的模块

时间:2019-07-17 23:59:58

标签: react-native expo

我正在尝试移植现有的RN应用程序以使用Expo。

我尝试了通常的步骤:终止Expo进程;垃圾节点模块; npm缓存清理; npm安装;守望者rm -fr $ TMPDIR /地铁*; rm -fr $ TMPDIR /匆忙*

/Users/matt/Documents/platform-prototype/XXXXXXXXXX/built/ios/debug/obj/XXXXXXXXXX/src/appWiring/ios/app.json:

{
  "name": "XXXXXXXX",
  "displayName": "XXXXXXXX",
  "expo": {
    "name": "XXXXXXXX",
    "slug": "xxxxxxxx",
    "entryPoint": "./index.js",
    "sdkVersion": "33.0.0",
    "version": "1.0",
    "platforms": [
      "ios",
      "android"
    ],
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "ios": {
      "supportsTablet": true
    }
  }
}

/Users/matt/Documents/platform-prototype/XXXXXXXXXX/built/ios/debug/obj/XXXXXXXXXX/src/appWiring/ios/index.js:

import App from "./App";
import { registerRootComponent } from "expo";
registerRootComponent(App);

/Users/matt/Documents/platform-prototype/XXXXXXXXXX/built/ios/debug/obj/XXXXXXXXXX/src/appWiring/ios/.babelrc:

{
  "presets": ["babel-preset-expo"],
  "plugins": [
    ["module-resolver", {
      "root": [
        "../../../",
        "../../../../platform-client-react/src",
        "../../../../platform-client-react-native/src"
      ],
      "alias": {
          "@platform-client-react" : "../../../../platform-client-react/src/",
          "@platform-client-react-native" : "../../../../platform-client-react-native/src/"
      },
    }],
  ]
}

/Users/matt/Documents/platform-prototype/XXXXXXXXXX/built/ios/debug/obj/platform-client-react/src/index.js:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const ConsoleLogger_1 = require("./platform/client-react/logger/ConsoleLogger");
etc. etc. etc.

当我尝试在iOS模拟器中运行该应用时,expo开发工具会显示此错误:

error: bundling failed: Error: Unable to resolve module `../../../../platform-client-react/src` from `/Users/matt/Documents/platform-prototype/XXXXXXXXXXX/built/ios/debug/obj/XXXXXXXXXXX/src/appWiring/ios/App.js`: The module `../../../../platform-client-react/src` could not be found from `/Users/matt/Documents/platform-prototype/XXXXXXXXXXX/built/ios/debug/obj/XXXXXXXXXXX/src/appWiring/ios/App.js`. Indeed, none of these files exist:

  * `/Users/matt/Documents/platform-prototype/XXXXXXXXXXX/built/ios/debug/obj/platform-client-react/src(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)`

  * `/Users/matt/Documents/platform-prototype/XXXXXXXXXXX/built/ios/debug/obj/platform-client-react/src/index(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx)`

实际上, /Users/matt/Documents/platform-prototype/XXXXXXXXXXX/built/ios/debug/obj/platform-client-react/src/index.js 文件确实存在,如您在上面看到的。我不知道为什么地铁捆扎机认为不行。

1 个答案:

答案 0 :(得分:0)

在“ 确实,这些文件都不存在”错误中说明了所有内容。 问题在于它正在寻找一个名为App.js的文件,而不是index.js。因此,要解决此问题,您只需创建一个App.js文件并通过该文件导出应用程序即可。