Content collections build: "Vite module runner has been closed."
crummy opened this issue · 5 comments
Astro Info
Astro v5.0.3
Node v23.2.0
System macOS (arm64)
Package Manager npm
Output static
Adapter none
Integrations none
Describe the Bug
I read files to generate a content collection. Works fine during development, but fails during build with this output:
❯ astro build
17:09:47 [content] Syncing content
17:09:47 [content] Content config changed
17:09:47 [content] Clearing content store
Vite module runner has been closed.
Location:
/home/projects/withastro-astro-7t9i3ppv/node_modules/vite/dist/node/module-runner.js:1217:13
Stack trace:
at SSRCompatModuleRunner.getModuleInformation (file:///home/projects/withastro-astro-7t9i3ppv/node_modules/vite/dist/node/module-runner.js:1217:13)
at request (file:///home/projects/withastro-astro-7t9i3ppv/node_modules/vite/dist/node/module-runner.js:1243:99)
at ./examples/csv/grammar.txt (/home/projects/withastro-astro-7t9i3ppv/src/content.config.ts:7:89)
at eval (file:///home/projects/withastro-astro-7t9i3ppv/node_modules/zod/lib/index.mjs:3492:40)
at eval (file:///home/projects/withastro-astro-7t9i3ppv/node_modules/astro/dist/content/content-layer.js:188:18)
What's the expected result?
Should behave identically to dev.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/withastro-astro-7t9i3ppv?file=src%2Fcontent.config.ts
In the console, run astro build
.
Participation
- I am willing to submit a pull request for this issue.
Ran into this issue updating an old website of mine, if an additional reproduction is needed: Princesseuh/astro-issues#1
Note that I do not use content collections
It happens to me any time I import a file in a collection. Here's the smallest repro I've come up with:
export const examples = defineCollection({
loader: async () => {
const file = await import('/src/examples/csv/grammar.txt');
return [];
},
});
Commenting out const file...
means build will succeed.
Ran into this issue updating an old website of mine, if an additional reproduction is needed: Princesseuh/astro-issues#1
On your repo I replaced this line:
const allStats = import.meta.glob("/src/data/*.json");
With this line:
const allStats = {}
And the error disappeared (it was replaced with a later error but presumably that's because this object is not expected to be empty).
I wondered if dynamic imports were broken entirely but I put this at the top of an astro file and it worked fine:
const f = await import("/src/examples/csv/grammar.txt?raw")