简体   繁体   English

未知的插件“ Relay”-React,GraphQL和Relay

[英]Unknown plugin “Relay” - React, GraphQL and Relay

I'm a beginner in GraphQL. 我是GraphQL的初学者。 I just started to follow the tutorial in Here But I'm getting this compilation problem: 我刚刚开始按照此处的教程进行操作,但是遇到了编译问题:

Unknown plugin "Relay" 未知的插件“中继”

This is my package.json 这是我的package.json

{
 "name": "hackernews-react-relay",
 "version": "0.1.0",
 "private": true,
 "dependencies": {
 "autoprefixer": "7.1.2",
 "babel-core": "^6.5.2",
 "babel-eslint": "7.2.3",
 "babel-jest": "20.0.3",
 "babel-loader": "7.1.1",
 "babel-preset-react-app": "^3.0.2",
 "babel-runtime": "6.26.0",
 "case-sensitive-paths-webpack-plugin": "2.1.1",
 "chalk": "1.1.3",
 "css-loader": "0.28.4",
 "dotenv": "4.0.0",
 "eslint": "4.4.1",
 "eslint-config-react-app": "^2.0.0",
 "eslint-loader": "1.9.0",
 "eslint-plugin-flowtype": "2.35.0",
 "eslint-plugin-import": "2.7.0",
 "eslint-plugin-jsx-a11y": "5.1.1",
 "eslint-plugin-react": "7.1.0",
 "extract-text-webpack-plugin": "3.0.0",
 "file-loader": "0.11.2",
 "fs-extra": "3.0.1",
 "html-webpack-plugin": "2.29.0",
 "jest": "20.0.4",
 "object-assign": "4.1.1",
 "postcss-flexbugs-fixes": "3.2.0",
 "postcss-loader": "2.0.6",
 "promise": "8.0.1",
 "react": "^15.6.1",
 "react-dev-utils": "^4.0.1",
 "react-dom": "^15.6.1",
 "react-relay": "^1.3.0",
 "style-loader": "0.18.2",
 "sw-precache-webpack-plugin": "0.11.4",
 "url-loader": "0.5.9",
 "webpack": "3.5.1",
 "webpack-dev-server": "2.7.1",
 "webpack-manifest-plugin": "1.2.1",
 "whatwg-fetch": "2.0.3"
},
 "scripts": {
 "start": "node scripts/start.js",
 "build": "node scripts/build.js",
 "test": "node scripts/test.js --env=jsdom"
},
"devDependencies": {
  "babel-plugin-relay": "^1.3.0",
  "relay-compiler": "^1.3.0"
},
  "jest": {
  "collectCoverageFrom": [
  "src/**/*.{js,jsx}"
],
"setupFiles": [
  "<rootDir>/config/polyfills.js"
],
"testMatch": [
  "<rootDir>/src/**/__tests__/**/*.js?(x)",
  "<rootDir>/src/**/?(*.)(spec|test).js?(x)"
],
"testEnvironment": "node",
"testURL": "http://localhost",
"transform": {
  "^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
  "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
  "^(?!.*\\.(js|jsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
"transformIgnorePatterns": [
  "[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"
],
"moduleNameMapper": {
  "^react-native$": "react-native-web"
},
"moduleFileExtensions": [
  "web.js",
  "js",
  "json",
  "web.jsx",
  "jsx",
  "node"
]
},
"babel": {
  "presets": [
    "react-app"
   ],
  "plugins": [
     "relay"
   ]
  },
    "eslintConfig": {
    "extends": "react-app"
  }
 }

I'm following step by step the tutorial mentioned above. 我将按照上述教程逐步进行操作。

OS: Ubuntu 17.04 Node 8.0.0 npm 5.0.0 操作系统:Ubuntu 17.04 Node 8.0.0 npm 5.0.0

I've already trying to solve this problem by adding this to babel-presets 我已经尝试通过将其添加到babel-presets来解决此问题

"es2015",
"stage-0",
"react"

and this to babel plugins 这是babel插件

"babel-relay-plugin-loader"

But nothing works. 但是什么都行不通。

Instead of providing a relay option in your plugins definition, you can create a file called for example babelRelayPlugin.js and put the plugin definition there since the plugin needs to load the schema before used. 除了在插件定义中提供中继选项之外,您还可以创建一个名为babelRelayPlugin.js的文件,然后将插件定义放在此处,因为插件需要在使用前加载架构。 There you can import the getBabelRelayPlugin pass in the schema and export it back. 在那里,您可以在模式中导入getBabelRelayPlugin传递,然后将其导回。

import getbabelRelayPlugin from 'babel-relay-plugin';
import schema from '../schema/schema.json';

export default getbabelRelayPlugin(schema.data);

Then use this file in your plugins definition instead. 然后在您的插件定义中使用此文件。

"babel": {
  "presets": [
    "react-app"
   ],
  "plugins": [
     "./babelRelayPlugin"
   ]
  },
    "eslintConfig": {
    "extends": "react-app"
  }
 }

note : I am assuming that both the package.json and the babelRelayPlugin.js files live in the same directory 注意 :我假设package.jsonbabelRelayPlugin.js文件都位于同一目录中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM