The Clog

Journal Articles Gitea

Content Frontmatter Causes `astro build` Error?

Another entry for this site. I ran pnpm run build after adding yesterday’s entry, and got this error:

✘ [ERROR] The build was canceled

end of the stream or a document separator is expected
  Hint:
    Browser APIs are not available on the server.

    If the code is in a framework component, try to access these objects after rendering using lifecycle methods or use a `client:only` directive to make the component exclusively run on the client.

    See https://docs.astro.build/en/guides/troubleshooting/#document-or-window-is-not-defined for more information.

  Location:
    .../blog-astro/src/content/journal-entries/2024-11-23.md:1:7
  Stack trace:
    at generateError (.../blog-astro/node_modules/.pnpm/[email protected]/node_modules/js-yaml/lib/js-yaml/loader.js:167:10)
    at readDocument (.../blog-astro/node_modules/.pnpm/[email protected]/node_modules/js-yaml/lib/js-yaml/loader.js:1545:5)
    at load (.../blog-astro/node_modules/.pnpm/[email protected]/node_modules/js-yaml/lib/js-yaml/loader.js:1614:19)
    at module.exports (.../blog-astro/node_modules/.pnpm/[email protected]/node_modules/gray-matter/lib/parse.js:12:17)
    at matter (.../blog-astro/node_modules/.pnpm/[email protected]/node_modules/gray-matter/index.js:50:10)
 ELIFECYCLE  Command failed with exit code 1.

I was obviously not using Browser APIs in an .md file. But, it did report that file as the culprit (specifically, the first line), so I checked it out.

---
title: @astrojs/node Build Error
date: 2024-11-23
---

<... rest of the file...>

I noticed the @ was a different color than the rest of the line. I thought YAML interprets any non-digit character as the start of a string; but just in case I wrapped the line in quotes, and it worked!

---
title: "@astrojs/node Build Error"
date: 2024-11-23
---

<... rest of the file...>

It seems that the @ character signals an import from another file, and obviously there wasn’t any so-named file.