React Native&继电器,兼容性。让他们一起工作的官方方式?

时间:2016-04-04 13:05:15

标签: react-native relay

前言:我是Javascript,Babel和React-Native的新手。

我一直在使用来自中继源的TodoMVC示例开发我的应用程序。我想知道是否有可能让React-Native + Relay轻松合作?

我设置了我的babelRelayPlugin并将其添加到我的.babelrc中。我为" react-relay":" ^ 0.7.3"安装了npm软件包。和" babel-relay-plugin":" ^ 0.7.3"但是在运行" npm install"和"反应原生的开始"我得到一个错误说"无法识别的模块' react-relay'" OR"未定义继电器"。

从阅读此帖子并查看最后一条评论(https://github.com/facebook/relay/issues/26#issuecomment-194570137),我觉得目前我应该使用TodoMVC作为新React-Native + Relay项目的基础。

这是对的吗?

这是我的.babelrc

{
  "env": {
    "development": {
      "passPerPreset": true,
      "presets": [
        {
          "plugins": [
            "./plugins/babelRelayPlugin"
          ]
        },
        "react-native"
      ]
    },
    "server": {
      "plugins": [
        "./plugins/babelRelayPlugin"
      ],
      "presets": [
        "es2015",
        "stage-0"
      ]
    }
  }
}

这是我的package.json

{
  "name": "testApp",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "clean:babelrc": "find ./node_modules -name react-packager -prune -o -name '.babelrc' -print | xargs rm -f",
    "postinstall": "npm run clean:babelrc",
    "start": "BABEL_ENV=server babel-node ./server.js",
    "update-schema": "babel-node ./scripts/updateSchema.js"
  },
  "dependencies": {
    "babel-preset-es2015": "^6.5.0",
    "babel-preset-react-native": "^1.5.1",
    "babel-preset-stage-0": "^6.5.0",
    "babel-relay-plugin": "^0.7.3",
    "express": "4.13.4",
    "express-graphql": "0.4.9",
    "graphql": "0.4.17",
    "graphql-relay": "0.3.6",
    "moment": "^2.12.0",
    "node-fetch": "^1.4.1",
    "react": "^0.14.5",
    "react-native": "^0.22.2",
    "react-native-animatable": "^0.5.2",
    "react-native-aws3": "0.0.1",
    "react-native-camera": "git+https://github.com/lwansbrough/react-native-camera.git",
    "react-native-console-panel": "0.0.7",
    "react-native-contacts": "^0.2.3",
    "react-native-keyboard-aware-scroll-view": "0.0.6",
    "react-relay": "^0.7.3",
    "sync-request": "^3.0.0",
    "uuid-v4": "^0.1.0"
  },
  "devDependencies": {
    "babel-cli": "^6.6.4",
    "flow-bin": "^0.22.1"
  },
  "engines": {
    "npm": ">=3"
  }
}

1 个答案:

答案 0 :(得分:0)

我成功解决了这个问题。我添加了" babel-core":" ^ 6.7.6"作为开发依赖。删除所有脚本并将项目从git克隆到新文件夹。一切都运行得很好!