{"record":{"id":"c2e8e7a3836d7dc3","repo":"gatsbyjs/gatsby","slug":"syntax-error-in-abspath-n-err-message-n-c","errorCode":null,"errorMessage":"Syntax error in \"${absPath}\":\\n${err.message}\\n${codeFrame}","messagePattern":"Syntax error in \"(.+?)\":\\\\n(.+?)\\\\n(.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby/src/bootstrap/resolve-module-exports.ts","lineNumber":42,"sourceCode":"  const code = fs.readFileSync(absPath, `utf8`) // get file contents\n\n  let ast\n  try {\n    ast = babelParseToAst(code, absPath)\n  } catch (err) {\n    if (err instanceof SyntaxError) {\n      // Pretty print syntax errors\n      const codeFrame = codeFrameColumns(\n        code,\n        {\n          start: (err as unknown as { loc: SourceLocation[\"start\"] }).loc,\n        },\n        {\n          highlightCode: true,\n        }\n      )\n\n      report.panic(\n        `Syntax error in \"${absPath}\":\\n${err.message}\\n${codeFrame}`\n      )\n    } else {\n      // if it's not syntax error, just throw it\n      throw err\n    }\n  }\n\n  let isCommonJS = false\n  let isES6 = false\n\n  // extract names of exports from file\n  traverse(ast, {\n    // Check if the file is using ES6 imports\n    ImportDeclaration: function ImportDeclaration() {\n      isES6 = true\n    },\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/bootstrap/resolve-module-exports.ts#L24-L60","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Open the file at absPath and the line/column shown in the code frame; fix the syntax error.","Run `node --check <absPath>` to validate syntax outside Gatsby.","If using new syntax, ensure the project's Babel/preset config supports it.","Restore the file from version control if it was truncated by a bad save."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate any module Gatsby will import before running the build:\nconst { execSync } = require('child_process')\ntry {\n  execSync(`node --check ${filePath}`, { stdio: 'inherit' })\n} catch {\n  process.exit(1) // syntax error; fix before gatsby sees it\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `node --check` on gatsby-node/gatsby-config/plugin files after editing.","Use an editor with JS syntax linting enabled.","Avoid unsupported syntax not covered by the project's Babel preset."],"tags":["syntax","babel","modules","plugin"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}