React-apollo: Can't resolve 'graphql/language/printer'

Created on 25 Oct 2017  路  33Comments  路  Source: apollographql/react-apollo

Using these deps:

"apollo-cache-inmemory": "^1.0.0",
"apollo-client": "^2.0.1",
"apollo-link": "^1.0.0",
"apollo-link-http": "^1.0.0",
"react": "^16.0.0",
"react-apollo": "^2.0.0",

I am getting this strange Module not found: Can't resolve 'graphql/language/printer' in apollo-client

I thought we're using graphql-tag?

Most helpful comment

I had to explicitly add graphql to my project dependencies to get this error to go away.

All 33 comments

I had to explicitly add graphql to my project dependencies to get this error to go away.

Getting a similar error using react-native

Failed building JavaScript bundle
Unable to resolve graphql/language/printer" from ".//node_modules/apollo-client/apollo.umd.js"

package.json:

--    "react-apollo": "^2.0.0",
--     "apollo-client": "^2.0.1"
--     "graphql-tag": "^2.5.0",

@spencercarli could you elaborate. thanks

I just ran yarn add graphql, restarted the React Native packager and this particular error went away. Still trying to figure out the rest of it 馃槃

@spencercarli That helped alot. Thanks :)

Been having issues lately related to apollo and apollo react... This apollo-client issue shows closely looking at package versions will help

Okay, just so everyone can get it to work, you need these:

"apollo-cache-inmemory": "^1.0.0",
"apollo-client": "^2.0.1",
"apollo-link": "^1.0.0",
"apollo-link-error": "^1.0.0",
"apollo-link-http": "^1.0.0",
"graphql": "^0.11.7",
"graphql-tag": "^2.5.0",
"react-apollo": "^2.0.0"

The non-obvious 2 packages to use to make [email protected] works are:

  • graphql
  • graphql-tag

Use it like so:

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

thanks @mech
resolved my problem with react native

Thank you! Knocked my head too long on setting up graphql.

Here are all the packages you'll need to get started, including graphql-tag & graphql: https://www.apollographql.com/docs/react/basics/setup.html#installation

Thanks for updating the docs @peggyrayzis :)

@peggyrayzis do we need to upgrade to "graphql": "^0.11.7" on our GraphQL server, as well? can't find this in the migration docs.

This still appears to be true as of today.

@agm1984 yes, I just had to deal with the issue right now .. but this post really helped

seems I met the same problem when using "graphql": "^0.13.2" in project, solved by downgrade it to "graphql": "0.13.0"

https://img.vim-cn.com/20/d41d110ef32b9a585a18d71a25a1c77b2749e5.png

@mech thanks

@peggyrayzis This is still a major problem. Even with a fresh build. Can you guys please look into it? Thanks

@mech Thanks! Adding graphql dependency worked!

September and still a problem.

upgraged graphql from 0.13-something to ^14 and bumped into this problem again

@iamdanthedev I'm having the same issue with this, and I'm using apollo server with merge-graphql-schemas :cry: Does anyone found a solution?

Don't know whether it needs to be another issue or not so I'll leave a comment here.
This problem occurs again in the new version of create-react-app which is using Babel 7 and Webpack 4...
Here is the error I've got:

Failed to compile.

./node_modules/apollo-link-state/lib/utils.js 21:51-56
  'graphql' does not contain an export named 'print'.

Code:

import ApolloClient from 'apollo-boost'
import gql from 'graphql-tag';

const client = new ApolloClient({
    uri: '/graphql'
})
console.log(gql)

npx create-react-app@next --scripts-version=@next test-next

I have same issue with [email protected], only my webpack gives me this error:

Attempted import error: 'print' is not exported from 'graphql'.

per each file I use import { print } from 'graphql'

When I downgrade to 0.13.0 I got dev server running, but there is runtime errors about undefined environment variables. I do not use create-react-app, I use react-static instead.

I have no idea where to dig, cos environment variables passed with any other version of graphql, but not with 0.13.0

Adding this worked for me:
```
import { ApolloProvider } from 'react-apollo'
import { BrowserRouter } from 'react-router-dom'
ReactDOM.render(



,
document.getElementById('root')
)
````

I think graphql is not installed as package.

npm install --save graphql
or
yarn add graphql

Hope fixes your problem!

installing
react-dom helped me

Esto funciono para mi:

npm install --save react-apollo graphql

For me it just was yarn add graphql and restarting the server

might help someone from going mad / bald: https://github.com/apollographql/apollo-client/issues/4764

Installing graphql solved the problem.

This was opened in 2017 and is tagged as Closed.

@peggyrayzis Should graphql continue to be installed separately if it is required by the lib?

This is still an ongoing issue. Using 3.0 beta on an Expo project and ran into the same problem. Installing graphql as suggested above solved the error.

@spencercarli Two + years later and your still helping out 馃

To me, the problem was not the missing dependency.
I had added graphql in the webpack alias resolver. Removing it from there fixed the problem. :)

I also had this issue when trying to create a webpack alias for graphql.

I encountered the same error.

Module not found: Can't resolve 'graphql/language/printer' ...

I installed npm i graphql and it gets solved.

Thank you everyone for the support.

This issue is still happening. I'm trying to use Apollo Client beta 3.0.0-rc.12

I have installed graphql and graphql-tag.

Was this page helpful?
0 / 5 - 0 ratings