cube-js/cube · error · Error

Syntax error during '${file.fileName}' parsing: ${error.mess

Error message

Syntax error during '${file.fileName}' parsing: ${error.message}:
${line}
${spaces}^

What it means

When the JS parser fails with a SyntaxError while compiling a schema file, Cube re-throws with a message that includes the file name, the parser message, the offending source line, and a caret pointing at the error column. This is a wrapped parser error to make the location human-readable.

Source

Thrown at packages/cubejs-schema-compiler/src/compiler/converters/CubeSchemaConverter.ts:156

          }
        }
      },
    });
  }

  protected parseJS(file: SchemaFile) {
    try {
      return parse(file.content, {
        sourceFilename: file.fileName,
        sourceType: 'module',
        plugins: ['objectRestSpread'],
      });
    } catch (error: any) {
      if (error.toString().indexOf('SyntaxError') !== -1) {
        const line = file.content.split('\n')[error.loc.line - 1];
        const spaces = Array(error.loc.column).fill(' ').join('');

        throw new Error(`Syntax error during '${file.fileName}' parsing: ${error.message}:\n${line}\n${spaces}^`);
      }

      throw error;
    }
  }

  public async generate(cubeName?: string) {
    await this.prepare(cubeName);

    this.converters.forEach((converter) => {
      converter.convert(this.parsedFiles);
    });
  }

  public getSourceFiles() {
    return Object.entries(this.parsedFiles).map(([cubeName, file]) => {
      const source = 'ast' in file
        ? generator(file.ast, {}).code

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Read the caret position in the message to find the exact file, line, and column
  2. Fix the syntax problem on the reported line (usually a missing brace, comma, or parenthesis)
  3. Run the file through node --check or your editor's linter to validate the whole file
  4. Check git diff for recently edited schema files if the error appeared after a merge

Example fix

// before (SyntaxError: missing comma)
cube('orders', {
  sql: () => `SELECT * FROM orders`
  measures: { count: { type: 'count' } }
});
// after
cube('orders', {
  sql: () => `SELECT * FROM orders`,
  measures: { count: { type: 'count' } }
});
Defensive patterns

Strategy: try-catch

Validate before calling

// check schema files before compiling
const { execSync } = require('child_process');
execSync(`node --check ${schemaFilePath}`);

Try / catch

try {
  await compiler.compile();
} catch (e) {
  if (e.message.startsWith('Syntax error during')) {
    // message already contains file, line, and caret — surface it verbatim
    console.error(e.message);
    process.exitCode = 1;
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Any syntactically invalid JavaScript in a .js data model file under the schema directory — missing brackets/commas, stray keywords, invalid syntax — processed by CubeSchemaConverter.parseJS.

Common situations: Typos while editing schema files; merging branches with conflicting edits; paste errors leaving truncated code; using syntax unsupported by the parser version.

Related errors


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