Last modified: Jul 02, 2026

Fix Express-GraphQL Module Error

Encountering the "Cannot find module 'express-graphql'" error in Node.js can stop your development workflow. This error usually means the package is missing or not installed correctly.

This guide will help you fix the error quickly. You will learn the common causes and step-by-step solutions.

Why This Error Happens

The error occurs when Node.js cannot locate the express-graphql module in your project's node_modules folder. This often happens after cloning a repository or after a failed installation.

Other reasons include using an outdated version of Node.js or having a typo in your package.json file. Sometimes, the module is installed globally instead of locally.

If you face similar issues with other packages, check our guide on Fix Node.js Error: Cannot find module for broader solutions.

Step 1: Install express-graphql Locally

The most common fix is to install the package locally in your project directory. Open your terminal and navigate to your project root.

Run the following command:


npm install express-graphql

This command installs the package and adds it to your node_modules folder. It also updates the package.json file.

If you are using Yarn, use this command instead:


yarn add express-graphql

After installation, try starting your application again. The error should be resolved.

Step 2: Check Your package.json File

If the error persists, verify that the module is listed in your package.json file. Open the file and look for express-graphql under dependencies.

Here is an example of a correct package.json entry:


{
  "dependencies": {
    "express-graphql": "^0.12.0"
  }
}

If it is missing, add it manually and run npm install again. This ensures all dependencies are installed correctly.

Step 3: Delete node_modules and Reinstall

Sometimes the node_modules folder gets corrupted. Deleting it and reinstalling all dependencies can fix the issue.

Run these commands in your project directory:


# Remove the node_modules folder
rm -rf node_modules

# Remove the package-lock.json file
rm -f package-lock.json

# Reinstall all dependencies
npm install

On Windows, use rd /s /q node_modules to delete the folder. This fresh install often resolves module-related errors.

Step 4: Verify Node.js and npm Versions

An outdated Node.js version can cause compatibility issues. Check your current versions with these commands:


node --version
npm --version

Ensure you are using a stable version. The express-graphql package works best with Node.js 12 or higher. If your version is older, update it from the official Node.js website.

Step 5: Check for Typo in Import Statement

A simple typo in your code can trigger the error. Double-check your import or require statement.

Here is the correct way to import the module:


// Correct import statement
const { graphqlHTTP } = require('express-graphql');

Make sure the package name is spelled exactly as express-graphql. Avoid using uppercase letters or extra spaces.

Step 6: Use the Correct Module Path

If you installed the package globally, Node.js may not find it. Always install it locally in your project.

You can check if the module exists by listing the node_modules folder:


ls node_modules | grep express-graphql

If it does not appear, install it locally as shown in Step 1.

Example Code and Output

Here is a simple Express server using express-graphql:


const express = require('express');
const { graphqlHTTP } = require('express-graphql');
const { buildSchema } = require('graphql');

// Define a schema
const schema = buildSchema(`
  type Query {
    hello: String
  }
`);

// Define a resolver
const root = {
  hello: () => 'Hello, world!',
};

// Create an Express app
const app = express();

// Use the graphqlHTTP middleware
app.use('/graphql', graphqlHTTP({
  schema: schema,
  rootValue: root,
  graphiql: true,
}));

// Start the server
app.listen(4000, () => {
  console.log('Server running on http://localhost:4000/graphql');
});

When you run this code with node app.js, you should see the following output:


Server running on http://localhost:4000/graphql

If you get the "Cannot find module" error, revisit the steps above. The code will work once the module is installed correctly.

Conclusion

The "Cannot find module 'express-graphql'" error is common but easy to fix. Always install the package locally in your project directory.

Check your package.json file and reinstall dependencies if needed. Verify your Node.js version and correct any typos in your code.

For more help with module errors, read our guide on Fix Node.js Error: Cannot find module. This will help you handle similar issues in the future.

With these steps, you can quickly resolve the error and continue building your GraphQL API with Express.