diff --git a/.changeset/bumpy-experts-melt.md b/.changeset/bumpy-experts-melt.md new file mode 100644 index 000000000000..97831773c14d --- /dev/null +++ b/.changeset/bumpy-experts-melt.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a bug in live collections that caused it to incorrectly complain about the collection being defined in the wrong file diff --git a/packages/astro/src/content/config.ts b/packages/astro/src/content/config.ts index aa7d70439ef9..e16b4d6c9fe8 100644 --- a/packages/astro/src/content/config.ts +++ b/packages/astro/src/content/config.ts @@ -12,7 +12,7 @@ function getImporterFilename() { !line.includes('defineCollection') && !line.includes('defineLiveCollection') && !line.includes('getImporterFilename') && - line !== 'Error', + !line.startsWith('Error'), ); if (!stackLine) { return undefined; @@ -113,7 +113,7 @@ export function defineLiveCollection< S extends BaseSchema | undefined = undefined, >(config: LiveCollectionConfig): LiveCollectionConfig { const importerFilename = getImporterFilename(); - if (!importerFilename?.includes('live.config')) { + if (importerFilename && !importerFilename.includes('live.config')) { throw new AstroError({ ...AstroErrorData.LiveContentConfigError, message: AstroErrorData.LiveContentConfigError.message(