Apollo-server: ApolloServer is not a constructor

Created on 4 Jul 2018  路  11Comments  路  Source: apollographql/apollo-server

I'm trying apollo-server-express for the first time so please pardon me for any mistake.

I tried to build an apollo server express app as a middleware but it gives the following error

C:\Files\Projects\dist\apollo\app.js:7
const server = new ApolloServer({
               ^

TypeError: ApolloServer is not a constructor
    at Object.<anonymous> (C:\Files\Projects\dist\apollo\app.js:7:16)
                                               ader.js:678:30)    at Module._compile (internal/modules/cjs/lomodules/cjs/loader.js:689ader.js:678:30)    at Object.Module._extensions..js (internal/.js:589:32)
modules/cjs/loader.js:                         er.js:528:12)689:10)                                        cjs/loader.js:520:3)

My code

const express = require('express');
const { ApolloServer } = require('apollo-server-express')
const schema = require('./Schema');

const app = express();

const server = new ApolloServer({
    schema
});

server.applyMiddleware({ app });

const PORT = process.env.PORT || 4000;
app.listen(PORT, () => {
    console.log(`馃殌 Server ready at http://localhost:4000${server.graphqlPath}`)
})

Most helpful comment

Make sure you installed rc version of apollo-server-express:

npm install --save apollo-server-express@rc

All 11 comments

The contents of your package.json?

Make sure you installed rc version of apollo-server-express:

npm install --save apollo-server-express@rc

Thank you @danilobuerger and @chentsulin! Only the rc tagged packages export the ApolloServer constructor now.

@SunilDy https://www.apollographql.com/slack is a great way to get these types of questions answered quickly

I ran into the same issue. Should the docs here be updated?
https://www.apollographql.com/docs/react/recipes/meteor

@jaredtmartin Were you able to fix the blocker you raised, kindly provide how you solved it.

facing the same issue, but appearently:

npm install --save apollo-server-express@rc

doesn't fix the problem for me (with meteor:apollo)

Is this error going to be fixed any time soon? Even if I install manually apollo-server-express@rc and save it to package.json, the error is back once I rebuild the docker image.

I'm seeing this as well following this: https://www.apollographql.com/docs/react/recipes/meteor.html

Hi, I am still getting the same error. Can anybody help me?

Hi, I am getting the same error.

I caught into the same issue. It resolved after deleting package.json, package-lock.json, node_modules and then installing again. Please confirm you have the latest version

Was this page helpful?
0 / 5 - 0 ratings