graphql-yoga: Error: Cannot find module 'graphql-middleware'

I get Error: Cannot find module 'graphql-middleware' after update graphql-yoga 1.16.2 to higher version any idea?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 21

Most upvoted comments

Seems like you should read the docs / changelog.

Ya, I tried. It lead to another issue

C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\validation.js:24
            throw new MiddlewareError("Type " + type + " exists in middleware but is missing in Schema.");
            ^

Error: Type generator exists in middleware but is missing in Schema.
    at new MiddlewareError (C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\validation.js:49:23)
    at C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\validation.js:24:19
    at Array.forEach (<anonymous>)
    at Object.validateMiddleware (C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\validation.js:22:29)
    at addMiddlewareToSchema (C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\middleware.js:19:40)
    at normalisedMiddlewares.reduceRight.schema (C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\middleware.js:57:18)
    at Array.reduceRight (<anonymous>)
    at applyMiddlewareWithOptions (C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\middleware.js:55:77)
    at applyMiddleware (C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\node_modules\graphql-middleware\dist\middleware.js:84:39)
    at new GraphQLServer (C:\Users\Lenovo\Desktop\prisma-backend\node_modules\graphql-yoga\dist\index.js:116:59)

It did not work like this on 1.16.2

What worked for me was deleting yarn.lock and installing again.

Same thing for me, definitely some form of dependency bug. Switching back to graphql-yoga@1.16.2 helps.

@bmirkalami remove line 1 completely. Node cannot understand that.

@bmirkalami You said you “uncommented” the require syntax. Did you then remove the “import” line in all required files?

const { GraphQLServer } = require('graphql-yoga')

const typeDefs = `
  type Query {
    hello(name: String): String!
  }
`

const resolvers = {
  Query: {
    hello: (_, { name }) => `Hello ${name || 'World'}`,
  },
}

const server = new GraphQLServer({ typeDefs, resolvers })
server.start(() => console.log('Server is running on localhost:4000'))

Also, are you having the same error as the original issue? Or still have the “Unexpected token import” error? If youre still getting the import error then you are missing an import line somewhere. If its the original issue then YAY, we’re back to the original issue but Im not exactly sure how to help as dependancies can be tricky if they get out of whack, when in doubt delete the node_modules folder and package-lock.json/yarn.lock files. Then try reinstalling the latest graphql-yoga. Outside of that Im not sure I can help at the moment.

@bmirkalami Please correct me if I’m wrong but it seems like you might be unfamiliar with how to properly use “technically” experimental javascript syntax, like import. You cannot run node index.js on a file with an import statement. That syntax is not supported in node…yet. You need to compile that code to something node can understand. The most common way to do that is by using https://babeljs.io/. I would suggest looking at babel’s site and on Stack Overflow for more information about how to do this: https://stackoverflow.com/questions/45854169/how-can-i-use-an-es6-import-in-node, but this issue is not the place for that discussion. IMHO It’s defintely worth knowing the babel ecosystem and how to use it properly, a bit confusing at first but makes life MUCH easier in the long run when working in the browser and in node. Good luck! 😉

@bmirkalami Usually an “Unexpected token import” points to a problem in the transpile. Are you using babel to transpile ES6/7 code? If not, you’ll need to use const { GraphQLServer } = require("graphql-yoga");