2

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

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

我设置了我的 babelRelayPlugin 并将其添加到我的 .babelrc 中。我为 "react-relay":"^0.7.3" 和 "babel-relay-plugin": "^0.7.3" 安装了 npm 包,但是在运行 "npm install" 和 "react-native start" 之后,我要么得到错误提示“无法识别模块'react-relay'”或“未定义中继”。

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

这个对吗?

这是我的 .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"
  }
}
4

1 回答 1

1

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

于 2016-04-12T15:26:56.093 回答