'TypeError: (0 , _expressGraphql2.default) is not a function

Trying to create a server for my application using graphQL server, but keep getting the error below. I have tried debugging with similar issues on this site but nothing seems to be working. I don't know where the "(0 , _expressGraphql2.default)" is even coming from, as it doesn't seem to be anywhere in the file.

TypeError: (0 , _expressGraphql2.default) is not a function
    at Object.<anonymous> (C:/Users/Jaewon/VMSFinal/workout-api/index.js:22:3)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at loader (C:\Users\Jaewon\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-register\lib\node.js:144:5)
    at Object.require.extensions.<computed> [as .js] (C:\Users\Jaewon\AppData\Roaming\npm\node_modules\babel-cli\node_modules\babel-register\lib\node.js:154:7)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at Object.<anonymous> (C:\Users\Jaewon\AppData\Roaming\npm\node_modules\babel-cli\lib\_babel-node.js:154:22)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
[nodemon] app crashed - waiting for file changes before starting...

Here is my index.js that the error is flagging

import express from "express";
import graphlHTTP from "express-graphql";
import mongoose from "mongoose";
import schema from "./schema";

mongoose.Promise = global.Promise;
mongoose.connect("mongodb://localhost/workout_db", {
  useNewUrlParser: true,
  useUnifiedTopology: true
});

const app = express();
const PORT = 4300;
app.get("/", (req, res) => {
  res.json({
    message: "Notetaking API v1"
  });
});

app.get(
  '/graphql',
  graphlHTTP({
    schema: schema,
    graphiql: true
  })
);

app.listen(PORT, () => {
  console.log(`Server is listening on PORT ${PORT}`);
});

package.json that is running index.js

{
  "dependencies": {
    "-": "^0.0.1",
    "babel-cli": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-stage-0": "^6.24.1",
    "express": "^4.17.1",
    "express-graphql": "^0.12.0",
    "graphql": "^15.7.2",
    "graphql-tools": "^8.2.0",
    "mongoose": "^6.0.13",
    "nodemon": "^2.0.15",
    "react-router-dom": "^6.0.2",
    "save-dev": "^0.0.1-security"
  },
  "name": "vmsfinal",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon ./index.js --exec babel-node -e js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "devDependencies": {
    "@babel/cli": "^7.16.0",
    "@babel/core": "^7.16.0",
    "@babel/node": "^7.16.0",
    "@babel/preset-env": "^7.16.4"
  }
}


Solution 1:[1]

This solves the problem: import { graphqlHTTP } from "express-graphql";

Hope it helps any traveler learning graphQL <3

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Matheus Gomes