Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse is not a function #155

Closed
lfernando-silva opened this issue Feb 16, 2018 · 21 comments
Closed

parse is not a function #155

lfernando-silva opened this issue Feb 16, 2018 · 21 comments

Comments

@lfernando-silva
Copy link

lfernando-silva commented Feb 16, 2018

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?

@jnwng
Copy link
Contributor

jnwng commented Feb 17, 2018

@lfernando-silva we establish graphql-js as a peerDependency. can you make sure that's installed?

@rogchap
Copy link

rogchap commented Feb 17, 2018

I have the same issue on a fresh new create-react-app.
I've made sure graphql-js is installed an all the typescript definitions for parse is resolving in my IDE, just not in the browser.

@rogchap
Copy link

rogchap commented Feb 17, 2018

Ok, I found the issue: does not work with the latest graphql@0.13.0 you must use graphql@0.12.3

@DogPawHat
Copy link

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.

@sznrbrt
Copy link

sznrbrt commented Feb 17, 2018

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

@DogPawHat
Copy link

DogPawHat commented Feb 18, 2018

Working setup for me (Typescript) is same as above, with react-apollo at 2.1.0-beta.2, and @types\graphql@0.12.4 and @types\props-types@15.5.2 (which I believe is a separate issue with react-apollo)

@lfernando-silva
Copy link
Author

For me, as @sznrbrt and @DogPawHat said, downgrading the graphql version to 0.13.0 works. Really, seems it's a problem with graphql module. Thank you guys

@sebkamil
Copy link

Is there an open issue on the graphql repo for this? I'd like to know when I can go past 0.13.0 Thanks

@DogPawHat
Copy link

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

@jnwng
Copy link
Contributor

jnwng commented Mar 22, 2018

i believe this is an issue upstream. see graphql/graphql-js#1248. closing for now!

@jnwng
Copy link
Contributor

jnwng commented Apr 3, 2018

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

@datlife
Copy link

datlife commented Apr 8, 2018

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 .

@cooperka
Copy link

cooperka commented Apr 9, 2018

@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.

@mikelax
Copy link

mikelax commented Apr 14, 2018

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

@nfantone
Copy link

nfantone commented May 9, 2018

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

@donovanhiland
Copy link

donovanhiland commented May 17, 2018

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

graphql/graphql-js#1248 (comment)

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

@wtfleming
Copy link

wtfleming commented May 19, 2018

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

@andykenward
Copy link

andykenward commented May 22, 2018

@wtfleming webpack extensions change for .mjs solved the issue for graphql@0.13.2 for me using webpack@3.11.0. Thanks

@mozillo
Copy link

mozillo commented May 23, 2018

My versions of graphql and graphql-tag never changed.

    "graphql": "^0.12.3",
    "graphql-tag": "^2.6.1",

Same issue, work fine before updating yarn.lock
show

TypeError: parse is not a function
parseDocument
node_modules/graphql-tag/src/index.js:129
  126 |   return docCache[cacheKey];
  127 | }
  128 | 
> 129 | var parsed = parse(doc, { experimentalFragmentVariables: experimentalFragmentVariables });
  130 | if (!parsed || parsed.kind !== 'Document') {
  131 |   throw new Error('Not a valid GraphQL document.');
  132 | }

after updating yarn.lock

shir added a commit to metastudio/cashbox-frontend that referenced this issue May 28, 2018
@jnwng
Copy link
Contributor

jnwng commented May 28, 2018

this seems like an issue with graphql-js with resolutions provided above (resolving .mjs after .js). i dont have much control over that here since we depend on graphql-js as a peerDependency, so i'm going to close this again. for reference, this seems to be the resolution: #155 (comment)

please re-open if you're having this issue with graphql@0.13.2 and the .mjs resolution steps above did not resolve the issue you're having here.

@jnwng jnwng closed this as completed May 28, 2018
bryankennedy added a commit to cns-iu/xmacroscope that referenced this issue Jun 1, 2018
Not sure why, but Webpack is causing errors after upgrading to the
latest graphql. Switching the order of JS loading fixes the issue.
Credit to:
apollographql/graphql-tag#155 (comment)
@cooperka
Copy link

cooperka commented Jun 6, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests