Parse-server: Cannot read property 'parseGraphQLController' of undefined

Created on 5 Apr 2020  路  4Comments  路  Source: parse-community/parse-server

Issue Description

Hello,

I am getting the following error when I create the GraphQL server with express:

TypeError: Cannot read property 'parseGraphQLController' of undefined
    at new ParseGraphQLServer (some-path\node_modules\parse-server\src\GraphQL\ParseGraphQLServer.js:27:59)
    at Object.<anonymous> (some-path\src\index.ts:33:30)
    at Module._compile (internal/modules/cjs/loader.js:1151:30)
    at Module.m._compile (some-path\node_modules\ts-node\src\index.ts:837:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:1171:10)
    at Object.require.extensions.<computed> [as .ts] (some-path\node_modules\ts-node\src\index.ts:840:12)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at main (some-path\node_modules\ts-node\src\bin.ts:226:14)

Steps to reproduce

The code that I wrote is the following. All I do is create a Parse server + graphQL + dashboard, as follows:

   const app = express();
  const PORT = process.env.PORT;
  const api = new ParseServer({
    databaseURI: process.env.DB_URI,
    cloud: (getEnv() === "development") ?
      path.join(__dirname, "cloud.ts") : // on development, use the ts file
      path.join(__dirname, "cloud.js"),
    appId: process.env.APP_ID,
    fileKey: process.env.FILE_KEY,
    masterKey: process.env.MASTER_KEY,
    serverURL: process.env.SERVER_URL,
    publicServerURL: process.env.SERVER_URL,
  });

  const parseGraphQLServer = new ParseGraphQLServer(
    api,
    {
      graphQLPath: '/graphql',
      playgroundPath: '/playground'
    }
  );

  const dashboard = new ParseDashboard({
    apps: [
      {
        serverURL: process.env.SERVER_URL, // http://localhost:1337/parse
        graphQLServerURL: process.env.SERVER_GRAPHQL_URL, // http://localhost:1337/graphql
        appId: process.env.APP_ID,
        masterKey: process.env.MASTER_KEY,
        appName: process.env.APP_NAME
      }
    ]
  });

  app.use("/parse", api.app);
  parseGraphQLServer.applyGraphQL(app);
  parseGraphQLServer.applyPlayground(app);
  app.use("/dashboard", dashboard);

  app.listen(PORT, () => {
    // tslint:disable-next-line
    console.log(`App running on port ${PORT}`);
  });

Expected Results

The GraphQL endpoint should be mounted correctly and the application should not crash.

Actual Outcome

The application crashes due to an error with the GraphQL srever

Environment Setup

  • Server

    • parse-server version: ^4.2.0
    • Operating System: Windows 10
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): loclahost
  • Database

    • MongoDB version: 4.2.3
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): localhost

My dependencies are:

  "dependencies": {
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "parse": "^2.12.0",
    "parse-dashboard": "^2.0.5",
    "parse-server": "^4.2.0"
  }

Most helpful comment

Can you please share how you are importing the ParseServer and ParseGraphQLServer vars? You should try something like this:

const { default: ParseServer, ParseGraphQLServer } = require('parse-server');

Hi @davimacedo, I got a new error after I changing the code.

2021-03-11T05:44:15.630914+00:00 app[web.1]: > node index.js
2021-03-11T05:44:15.630914+00:00 app[web.1]: 
2021-03-11T05:44:18.757458+00:00 app[web.1]: /app/node_modules/express/lib/router/index.js:458
2021-03-11T05:44:18.757487+00:00 app[web.1]:       throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
2021-03-11T05:44:18.757489+00:00 app[web.1]:       ^
2021-03-11T05:44:18.757489+00:00 app[web.1]: 
2021-03-11T05:44:18.757490+00:00 app[web.1]: TypeError: Router.use() requires a middleware function but got a Object
2021-03-11T05:44:18.757491+00:00 app[web.1]:     at Function.use (/app/node_modules/express/lib/router/index.js:458:13)
2021-03-11T05:44:18.757493+00:00 app[web.1]:     at Function.<anonymous> (/app/node_modules/express/lib/application.js:220:21)
2021-03-11T05:44:18.757494+00:00 app[web.1]:     at Array.forEach (<anonymous>)
2021-03-11T05:44:18.757495+00:00 app[web.1]:     at Function.use (/app/node_modules/express/lib/application.js:217:7)
2021-03-11T05:44:18.757495+00:00 app[web.1]:     at Object.<anonymous> (/app/index.js:47:7)
2021-03-11T05:44:18.757495+00:00 app[web.1]:     at Module._compile (node:internal/modules/cjs/loader:1092:14)
2021-03-11T05:44:18.757496+00:00 app[web.1]:     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
2021-03-11T05:44:18.757496+00:00 app[web.1]:     at Module.load (node:internal/modules/cjs/loader:972:32)
2021-03-11T05:44:18.757496+00:00 app[web.1]:     at Function.Module._load (node:internal/modules/cjs/loader:813:14)
2021-03-11T05:44:18.757497+00:00 app[web.1]:     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)

All 4 comments

Can you please share how you are importing the ParseServer and ParseGraphQLServer vars? You should try something like this:

const { default: ParseServer, ParseGraphQLServer } = require('parse-server');

Hello @davimacedo,
Thank youy so much, I confirm it's working :)
Juan

Can you please share how you are importing the ParseServer and ParseGraphQLServer vars? You should try something like this:

const { default: ParseServer, ParseGraphQLServer } = require('parse-server');

Hi @davimacedo, I got a new error after I changing the code.

2021-03-11T05:44:15.630914+00:00 app[web.1]: > node index.js
2021-03-11T05:44:15.630914+00:00 app[web.1]: 
2021-03-11T05:44:18.757458+00:00 app[web.1]: /app/node_modules/express/lib/router/index.js:458
2021-03-11T05:44:18.757487+00:00 app[web.1]:       throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
2021-03-11T05:44:18.757489+00:00 app[web.1]:       ^
2021-03-11T05:44:18.757489+00:00 app[web.1]: 
2021-03-11T05:44:18.757490+00:00 app[web.1]: TypeError: Router.use() requires a middleware function but got a Object
2021-03-11T05:44:18.757491+00:00 app[web.1]:     at Function.use (/app/node_modules/express/lib/router/index.js:458:13)
2021-03-11T05:44:18.757493+00:00 app[web.1]:     at Function.<anonymous> (/app/node_modules/express/lib/application.js:220:21)
2021-03-11T05:44:18.757494+00:00 app[web.1]:     at Array.forEach (<anonymous>)
2021-03-11T05:44:18.757495+00:00 app[web.1]:     at Function.use (/app/node_modules/express/lib/application.js:217:7)
2021-03-11T05:44:18.757495+00:00 app[web.1]:     at Object.<anonymous> (/app/index.js:47:7)
2021-03-11T05:44:18.757495+00:00 app[web.1]:     at Module._compile (node:internal/modules/cjs/loader:1092:14)
2021-03-11T05:44:18.757496+00:00 app[web.1]:     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
2021-03-11T05:44:18.757496+00:00 app[web.1]:     at Module.load (node:internal/modules/cjs/loader:972:32)
2021-03-11T05:44:18.757496+00:00 app[web.1]:     at Function.Module._load (node:internal/modules/cjs/loader:813:14)
2021-03-11T05:44:18.757497+00:00 app[web.1]:     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)

Same problem. Cant get it running.

Was this page helpful?
0 / 5 - 0 ratings