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

TypeError: buildSchema is not a function #2812

Closed
dschinkel opened this issue Sep 29, 2020 · 1 comment
Closed

TypeError: buildSchema is not a function #2812

dschinkel opened this issue Sep 29, 2020 · 1 comment

Comments

@dschinkel
Copy link

dschinkel commented Sep 29, 2020

I do not know how to make this "happy". And I've spent hours on this...about had it.

the package.json in the folder with this code is as a "type"="module"

api.ts

import compression from 'compression';
import express from 'express';

import * as expressGraphQL from 'express-graphql';
import * as graphQL from 'graphql';

const { graphqlHTTP } = expressGraphQL;
const { buildSchema } = graphQL;

...
const App = express()
  .use(compression())
  .on('error', (err: any) => {
    console.log(err);
  })
  .use(
    '/graphql',
    graphqlHTTP({
      schema,
      rootValue: root,
      graphiql: true,
  })
);

export default App;

I'm not able to import buildSchema and get that working...no matter what I've tried so far.

The error I get now is a TS error:
TypeError: buildSchema is not a function

I already have these installed:

"@types/express-graphql": "^0.9.0",
"@types/graphql": "^14.5.0",

Also since this is an ESM I can't use require. So that route for import is not an option...I can't use const { graphql, buildSchema } = require('graphql');

And trying this route:

import { graphqlHTTP } from 'express-graphql';
import { buildSchema } from 'graphql';

Gave me:

import { buildSchema } from 'graphql';
         ^^^^^^^^^^^
SyntaxError: The requested module 'graphql' is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by importing the default export.
For example:
import pkg from 'graphql';
const { buildSchema } = pkg;

already posted this on stack, no responses.

@dschinkel
Copy link
Author

resolution of course, right after I post this, but this is all still such a pain in the ass

import pkg1 from 'express-graphql';

import pkg from 'graphql';

const { graphqlHTTP } = pkg1;

const { buildSchema } = pkg;

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

1 participant