{"record":{"id":"304d9b34dbe0e770","repo":"withastro/astro","slug":"compilererror","errorCode":"CompilerError","errorMessage":"${compilerError.text}","messagePattern":"\\$\\{compilerError\\.text\\}","errorType":"exception","errorClass":"CompilerError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/core/compile/compile.ts","lineNumber":100,"sourceCode":"\n\treturn {\n\t\t...transformResult,\n\t\tcss: transformResult.css.map((code, i) => ({\n\t\t\t...cssPartialCompileResults[i],\n\t\t\tcode,\n\t\t})),\n\t};\n}\n\nfunction handleCompileResultErrors(\n\tfilename: string,\n\tresult: TransformResult,\n\tcssTransformErrors: AstroError[],\n) {\n\tconst compilerError = result.diagnostics.find((diag) => diag.severity === 'error');\n\n\tif (compilerError) {\n\t\tthrow new CompilerError({\n\t\t\tname: 'CompilerError',\n\t\t\tmessage: compilerError.text,\n\t\t\tlocation: {\n\t\t\t\tline: compilerError.labels[0].line,\n\t\t\t\tcolumn: compilerError.labels[0].column,\n\t\t\t\tfile: filename,\n\t\t\t},\n\t\t\thint: compilerError.hint,\n\t\t});\n\t}\n\n\tswitch (cssTransformErrors.length) {\n\t\tcase 0:\n\t\t\tbreak;\n\t\tcase 1: {\n\t\t\tthrow cssTransformErrors[0];\n\t\t}\n\t\tdefault: {","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/withastro/astro/blob/3578d45d34226d63cff3d261c971c221de6794d2/packages/astro/src/core/compile/compile.ts#L82-L118","documentation":"`CompilerError` surfaces when the Astro compiler reports a diagnostic with severity `error` for a `.astro` file. The first error diagnostic is rethrown with its exact line/column (from the diagnostic's first label), the file, and the compiler's `hint` text. This is the normal channel for `.astro` syntax errors.","triggerScenarios":"A syntax error in an `.astro` file's frontmatter or template: unclosed tags, malformed expressions, invalid directive usage — anything the compiler flags at severity `error` while transforming that file.","commonSituations":"Typo in a template expression (`{title` without `}`), mismatched/unclosed component tags, invalid frontmatter JavaScript, using a directive with wrong arguments.","solutions":["Open the file and line/column reported in the error and fix the syntax.","Read the `hint` field — the compiler often states exactly what is malformed.","Comment out recently changed template blocks to narrow the location if the span is wide.","Check the Astro docs for the directive/component syntax you were writing."],"exampleFix":"<!-- before: src/pages/index.astro -->\n<h1>{title</h1>\n\n<!-- after -->\n<h1>{title}</h1>","handlingStrategy":"validation","validationCode":"# Catch component syntax errors before they surface in a build\nnpx astro check","typeGuard":null,"tryCatchPattern":"try {\n  await buildPage(file);\n} catch (err) {\n  if (err instanceof Error && err.name === 'CompilerError') {\n    showDiagnostic(err.message, err.loc?.file, err.loc?.line, err.loc?.column, err.hint);\n    return;\n  }\n  throw err;\n}","preventionTips":["Use the Astro language-server/editor extension for inline template diagnostics.","Run `astro check` in CI so syntax errors fail the pipeline, not the deploy.","Read the `hint` on the error — the compiler states what is malformed."],"tags":["compiler","syntax","astro-component"],"backgroundTag":"syntax-error","analyzedSha":"3578d45d34226d63cff3d261c971c221de6794d2","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}