Search code examples
reactjsnpmrelayjsrelayreact-relay

How to Compile React-Relay


I am trying to follow the official Relay documentation here.

After installing React-Relay:

npm install --save relay-runtime react-relay
npm install --save-dev relay-compiler graphql babel-plugin-relay

... and configuring package.json:

{
  ...
  "scripts": {
    ...
    "start": "npm run relay && react-scripts start",
    "build": "npm run relay && react-scripts build",
    "relay": "npm run relay-compiler --schema schema.graphql --src ./src/ --watchman false $@"
    ...
  },
  ...
}

when I ran:

npm start

I got the following error:

> [email protected] start D:\xampp\htdocs\my-react\test
> npm run relay && react-scripts start


> [email protected] relay D:\xampp\htdocs\my-react\test
> npm run relay-compiler --schema schema.graphql --src ./src/ --watchman false $@

npm ERR! missing script: relay-compiler

How can I correctly run relay-compiler?


Solution

  • Apparently, I must remove 'npm run' in the last line of package.json:

    {
      ...
      "scripts": {
        ...
        "start": "npm run relay && react-scripts start",
        "build": "npm run relay && react-scripts build",
        "relay": "relay-compiler --schema schema.graphql --src ./src/ --watchman false $@"
        ...
      },
      ...
    }