Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content collections build: "Vite module runner has been closed." #12689

Open
1 task done
crummy opened this issue Dec 9, 2024 · 9 comments
Open
1 task done

Content collections build: "Vite module runner has been closed." #12689

crummy opened this issue Dec 9, 2024 · 9 comments
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@crummy
Copy link

crummy commented Dec 9, 2024

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.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Dec 9, 2024
@Princesseuh
Copy link
Member

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

@Princesseuh Princesseuh added - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs triage Issue needs to be triaged labels Dec 11, 2024
@crummy
Copy link
Author

crummy commented Dec 11, 2024

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.

@crummy
Copy link
Author

crummy commented Dec 12, 2024

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")

crummy added a commit to crummy/ppegjs-demo that referenced this issue Dec 12, 2024
Simplifies content collection parsing, and there's this:
withastro/astro#12689
@Adammatthiesen
Copy link

can also confirm that this issue is happening with the following vite dynamic import functions from an integration hook (astro:config:setup) as well... we (StudioCMS team) had to disable our config file loading system (Load a users studiocms.config.{mjs|js|ts|mts|cjs|cts} in order to upgrade to v5). hopefully there will be a fix soon!

const mod = await import(configPath)

@bluwy
Copy link
Member

bluwy commented Dec 16, 2024

Maybe same as vitejs/vite#18962

@crummy
Copy link
Author

crummy commented Dec 19, 2024

I have a workaround, reading files with fs.readFile. Here is my loader:

    loader: async () => {
        const files = await fastGlob("src/examples/*.json");
        return await Promise.all(files.map(async f => {
            const contents = await fs.readFile(f, "utf-8")
            const json = JSON.parse(contents);
            return {
                id: json.title,
                title: json.title,
                grammar: json.grammar,
                input: json.input,
                highlighted: json.highlighted
            }
        }));
    },

@bluwy

This comment was marked as outdated.

@bluwy bluwy closed this as completed Jan 2, 2025
@bluwy

This comment was marked as outdated.

@mhagendoorn-9292
Copy link

This issue is still present in [email protected].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests

5 participants