gatsbyjs/gatsby · error

Syntax error in "${absPath}":\n${err.message}\n${codeFrame}

Error message

Syntax error in "${absPath}":\n${err.message}\n${codeFrame}

What it means

Thrown by Gatsby's resolve-module-exports when importing a user/plugin module throws a SyntaxError. The handler detects SyntaxError, builds a code frame from @babel/code-frame at the error's source location, and panics with the file path, message, and highlighted frame. It is specifically for parse-time errors so the user gets a readable location instead of a raw Node stack.

Source

Thrown at packages/gatsby/src/bootstrap/resolve-module-exports.ts:42

  const code = fs.readFileSync(absPath, `utf8`) // get file contents

  let ast
  try {
    ast = babelParseToAst(code, absPath)
  } catch (err) {
    if (err instanceof SyntaxError) {
      // Pretty print syntax errors
      const codeFrame = codeFrameColumns(
        code,
        {
          start: (err as unknown as { loc: SourceLocation["start"] }).loc,
        },
        {
          highlightCode: true,
        }
      )

      report.panic(
        `Syntax error in "${absPath}":\n${err.message}\n${codeFrame}`
      )
    } else {
      // if it's not syntax error, just throw it
      throw err
    }
  }

  let isCommonJS = false
  let isES6 = false

  // extract names of exports from file
  traverse(ast, {
    // Check if the file is using ES6 imports
    ImportDeclaration: function ImportDeclaration() {
      isES6 = true
    },

View on GitHub (pinned to 8b06340921)

Solutions

  1. Open the file at absPath and the line/column shown in the code frame; fix the syntax error.
  2. Run `node --check <absPath>` to validate syntax outside Gatsby.
  3. If using new syntax, ensure the project's Babel/preset config supports it.
  4. Restore the file from version control if it was truncated by a bad save.
Defensive patterns

Strategy: validation

Validate before calling

// Validate any module Gatsby will import before running the build:
const { execSync } = require('child_process')
try {
  execSync(`node --check ${filePath}`, { stdio: 'inherit' })
} catch {
  process.exit(1) // syntax error; fix before gatsby sees it
}

Prevention

When it happens

Trigger: Gatsby tries to import a gatsby-config/gatsby-node/plugin module; the file contains a JS syntax error (unclosed brace, bad token, unsupported syntax without a Babel transform). err instanceof SyntaxError is true, so this branch runs.

Common situations: Editing gatsby-node.js and saving mid-typing; using newer JS syntax not covered by the configured Babel preset; copy-pasting code that lost characters; a plugin file corrupted on disk; mismatched Babel config suppressing needed transforms.

Related errors


AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13). Data as JSON: /api/errors/c2e8e7a3836d7dc3. Report an issue: GitHub.