反应本机0.57.3。无法解析模块

时间:2018-10-17 09:29:24

标签: reactjs react-native

我的反应本机很干净。每次我运行react-native run-ios时,我似乎都会得到构建错误,指出找不到模块。我的代码看不到任何问题。

最近几天遇到此问题,然后转圈。

反应性:0.57.3 XCode:9.4.1

有什么想法吗?

模拟器屏幕警告在这里 Simulator screen shot

“ FirstScreen”代码在这里引用公共模块 FirstScreen code

Package.json

{
  "name": "client",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "16.6.0-alpha.8af6728",
    "react-native": "0.57.3",
    "react-navigation": "^3.0.0-alpha.6"
  },
  "devDependencies": {
    "@babel/plugin-external-helpers": "^7.0.0",
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.48.1",
    "react-test-renderer": "16.6.0-alpha.8af6728"
  },
  "jest": {
    "preset": "react-native"
  }
}

1 个答案:

答案 0 :(得分:1)

从您的文件夹结构来看,以下行是错误的:

import { Input, Button } from "../common";

由于编译器将查找名为common.js或common / index.js的文件。这些都不存在。

相反,您必须这样做:

import Input from "../common/Input";
import Button from "../common/Button";

或者,如果您仍然希望保留该行代码,则将名为index.js的文件添加到文件夹common,然后添加以下代码:

export { default as Input } from "./Input"
export { default as Button } from "./Button"