cube-js/cube · error · Error

Your express app config is missing body-parser middleware. T

Error message

Your express app config is missing body-parser middleware. Typical config can look like: `app.use(bodyParser.json({ limit: '50mb' }));`

What it means

The dev server's POST /playground/generate-schema endpoint reads req.body; if body parsing middleware is absent, req.body is undefined and this Error explains that express needs body-parser (json) configured.

Source

Thrown at packages/cubejs-server-core/src/core/DevServer.ts:164

      }
      res.json({ tablesSchema });
    }));

    app.get('/playground/files', catchErrors(async (req, res) => {
      this.cubejsServer.event('Dev Server Files Load');
      const files = await this.cubejsServer.repository.dataSchemaFiles();
      res.json({
        files: files.map(f => ({
          ...f,
          absPath: path.resolve(path.join(this.cubejsServer.repository.localPath(), f.fileName))
        }))
      });
    }));

    app.post('/playground/generate-schema', catchErrors(async (req, res) => {
      this.cubejsServer.event('Dev Server Generate Schema');
      if (!req.body) {
        throw new Error('Your express app config is missing body-parser middleware. Typical config can look like: `app.use(bodyParser.json({ limit: \'50mb\' }));`');
      }

      if (!req.body.tables) {
        throw new Error('You have to select at least one table');
      }

      const dataSource = req.body.dataSource || 'default';

      const driver = await this.cubejsServer.getDriver({
        dataSource,
        authInfo: null,
        securityContext: null,
        requestId: getRequestIdFromRequest(req),
      });
      const tablesSchema = req.body.tablesSchema || (await driver.tablesSchema());

      if (!Object.values(SchemaFormat).includes(req.body.format)) {
        throw new Error(`Unknown schema format. Must be one of ${Object.values(SchemaFormat)}`);

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Add app.use(bodyParser.json({ limit: '50mb' })) before mounting Cube/dev-server routes
  2. Or use express.json({ limit: '50mb' }) (built-in since Express 4.16)
  3. Verify req.body is parsed by logging it on a test POST

Example fix

// before
const app = express();
server.init(app);
// after
const app = express();
app.use(bodyParser.json({ limit: '50mb' }));
server.init(app);
Defensive patterns

Strategy: validation

Validate before calling

function requireBodyParser(app) {
  const probe = express();
  // ensure before mounting dev routes:
  if (!app._router) return;
  app.use(bodyParser.json({ limit: '50mb' }));
}

Try / catch

try { await fetch('/playground/generate-schema', {...}); } catch (e) { if (/body-parser middleware/.test(String(e))) { app.use(bodyParser.json({ limit: '50mb' })); } }

Prevention

When it happens

Trigger: Hitting the Playground's generate-schema route from an app whose express instance was created without bodyParser.json() — e.g. custom server setup bypassing cubejs-server's default middleware.

Common situations: Custom express servers mounting the Cube dev API without middleware, upgrading express (v4->v5 removing built-in body parsing nuances), or ordering middleware after routes.

Related errors


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/564828a667840bcb. Report an issue: GitHub.