graphql-tag: parse is not a function

I’am getting error at query declaration.

index.js:128 Uncaught TypeError: parse is not a function

Debugging, I realized the method parse at node_modules/graphql-tag/src/index.js is really undefined:

//node_modules/graphql-tag/src/index.js
var parser = require('graphql/language/parser');

var parse = parser.parse; //parse is undefined
//...
//line 128
var parsed = parse(doc); //parse is not a function

This is my code. I’m using create-react-app (v 1.5.1) and already tried to rewire. Also didn’t work with the example query.

import { graphql } from 'react-apollo'
import gql from 'graphql-tag'

const CREATE_USER_MUTATION = gql`  
mutation createUserMutation ($name: String, $email: String, $category: String, $phone: String, $defaultAddress: String, $image: String, $updatedAt: Int, $createdAt: Int) {
    createUser(name: $name, email: $email, category: $category, phone: $phone, defaultAddress: $defaultAddress, image: $image, updatedAt: $updatedAt, createdAt: $createdAt) {
      id
      name
      email
      category
      phone
      defaultAddress
      createdAt
    }
  }
`

export default graphql(CREATE_USER_MUTATION, {name: 'createUserMutation'})

The query can be parsed well at AST explorer.

Can anyone help me?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 22
  • Comments: 21 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I can confirm this is still an issue with graphql v0.13.2, downgrading to 0.13.0 worked for me as well.

Suggestion from @donovanhiland works for me too. For people like me coming to this from Google I had ejected from create-react-app and in config/webpack.config.prod.js and config/webpack.config.dev.js need to change the line

extensions: ['.re', '.ml', '.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],

to

extensions: ['.re', '.ml', '.web.js', '.js', '.json', '.web.jsx', '.jsx', '.mjs'],

in both files and this fixed it for me.

I’m using the ReasonReact scripts, so your config probably looks a bit different, but what is important is the .mjs comes after .js

I’m using react-static which has its own webpack config, so the suggested workaround for create-react-apps (resolving .mjs after .js) doesn’t help me. Here’s what worked.

Put it in a postinstall script so it runs automatically. Seems good enough for now, I’ve spent too many hours debugging this 💩

# Remove all .mjs files from graphql:
find node_modules/graphql -type f -name *.mjs | xargs rm

I would like to confirm that upgrading the react-scripts to 1.1.2 cleared the issue of parse is not a function. I am currently using create-react-app for client

npm install --save --save-exact react-scripts@1.1.2

Reference: graphql/graphql-js#1248 .

Just had the same issue, but downgrading back to 0.13.0 solved it. Thanks @DogPawHat! Working setup: apollo-boost@0.1.1 graphql@0.13.0 react-apollo@2.0.4

For anyone else out there reaching this from Google, this is still an issue with graphql@0.13.2.

Are you sure it’s 0.13.0 and not 0.13.1? There was a change to graphql-js that I think only broke graphql-tag. Issue is at graphq-js/#1248.

@sebkamil its at graphq-js/#1248. Still figuring it out it seems.

This seems to be the answer to the problem. For me at least.

https://github.com/graphql/graphql-js/issues/1248#issuecomment-378086769

It had to do with webpack resolving .mjs extensions before .js

@datlife I’ve been using react-scripts v1.1.2 but still getting the same type of error:

TypeError: graphql_1.parse is not a function
    at eval (introspectSchema.js?d6eb:40)

Downgrading to graphql v0.13.0 is still the only successful workaround for me so far.

Will have to take a closer look at importing GraphQL-js at 0.13 and 14.0