#[GenerateContentTypesError] on `astro sync` & `astro check`

7 messages · Page 1 of 1 (latest)

formal citrus
#

Hi!

I'm hoping someone can help me troubleshoot this issue: I created a very simple content collection and everything was working fine, I managed to access the entries just fine in dev mode and set the schema and all that... But when I ran the check & sync commands, I started getting this error:

[ERROR] [content] [GenerateContentTypesError] `astro sync` command failed to generate content collection types: module is not defined
  Hint:
    Check your `src/content/config.*` file for typos.
  Error reference:
    https://docs.astro.build/en/reference/errors/generate-content-types-error/
  Stack trace:
    at (...my home...)/Library/pnpm/store/v3/tmp/dlx-53773/node_modules/.pnpm/astro@4.8.2/node_modules/astro/dist/core/sync/index.js:110:11
    [...] See full stack trace in the browser, or rerun with --verbose.
  Caused by:
  module is not defined
    at eval (/(...my app...)/node_modules/.pnpm/cssesc@3.0.0/node_modules/cssesc/cssesc.js:112:1)
#

This cssesc is not a library I'm familiar with, but pnpm why tells me its related to eslint and stylelint in my setup, so I looked around and found and old issue mentioned here in this discord channel. It was supposedly fixed on a previous update and, as I was on astro 4.5.5 I decided to update my whole setup just in case. Now, in astro 4.8.2, I tried the same and I'm getting the following error:

[GenerateContentTypesError] `astro sync` command failed to generate content collection types: Failed to load url async_hooks (resolved id: async_hooks) in /(...my app...)/node_modules/.pnpm/p-limit@5.0.0/node_modules/p-limit/index.js. Does the file exist?
  Hint:
    Check your `src/content/config.*` file for typos.
  Error reference:
    https://docs.astro.build/en/reference/errors/generate-content-types-error/
  Stack trace:
    at syncContentCollections (file:///(...my app...)/node_modules/.pnpm/astro@4.8.2_@types+node@20.5.1_sass@1.72.0_typescript@5.4.2/node_modules/astro/dist/core/sync/index.js:110:11)
    at async AstroBuilder.run (file:///(...my app...)/node_modules/.pnpm/astro@4.8.2_@types+node@20.5.1_sass@1.72.0_typescript@5.4.2/node_modules/astro/dist/core/build/index.js:162:23)
    at async build (file:///(...my app...)/node_modules/.pnpm/astro@4.8.2_@types+node@20.5.1_sass@1.72.0_typescript@5.4.2/node_modules/astro/dist/cli/build/index.js:20:3)
    at async cli (file:///(...my app...)/node_modules/.pnpm/astro@4.8.2_@types+node@20.5.1_sass@1.72.0_typescript@5.4.2/node_modules/astro/dist/cli/index.js:168:5)
  Caused by:
  Failed to load url async_hooks (resolved id: async_hooks) in /(...my app...)/node_modules/.pnpm/p-limit@5.0.0/node_modules/p-limit/index.js. Does the file exist?
    at loadAndTransform (file:///(...my app...)/node_modules/.pnpm/vite@5.2.11_@types+node@20.5.1_sass@1.72.0/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:53884:21)

This p-limit is also unfamiliar to me, and seems that it's also related to eslint.

#

Also, dev mode is broken now too 😐

#

I've checked the config.ts file and it's perfectly well formed as far as I can see:

import { defineCollection, z } from 'astro:content';

const termsAndConditionsCollection = defineCollection({
  type: 'content',
  schema: z.object({
    title: z.string(),
    date: z.date(),
    language: z.string().length(2),
    pdfUrl: z.string(),
  }),
});

export const collections = {
  'terms-and-conditions': termsAndConditionsCollection,
};

I'm not sure why these things are interfering with content collections. What could I be doing wrong?

Thanks!

jaunty topaz
#

Hint: if you add a language (like, html or ts) after your first set of backticks on your code blocks, you'll get syntax highlighting, which will make your code easier for others to read. I think you can use sh or bash for terminal output too (not 100%).

If you've run a local build already, then I would delete the dist folder and see if that fixes it. I've had issues running astro sync on pnpm before, so I just run pnpm dev, which will generate your types.

Also, the issue might not be with the config, but with your content. Make sure it matches and you don't have special characters that aren't escaped or quoted.

Lastly, if your content is json, rather than md, then set your collection type to type: "data".

formal citrus
#

Hi Henri! First and foremost thanks for your help. I've double checked all of your hints and sadly nothing worked. What I noticed is that 1) I misspoke on my Friday's message, with the updates packages dev mode does still work, it fails on build which I can't say I tested with the old versions and 2) If I remove the src/content/config.ts file entirely, everything works (build, check and sync ). Haven't launched the app yet to see if the data loads (EDIT: it does work in dev mode too), but it seems that the configuration file being present it's the thing that triggers the error, maybe it's the schema check?

jaunty topaz
#

The schema and the contents have to be in sync for Astro to generate the types. Where is your data? According to your above config.ts, it should be in src/content/terms-and-conditions/terms1.md or similar. Right?

Can you share the frontmatter portion of one of these files?