-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Comments
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 |
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") |
Simplifies content collection parsing, and there's this: withastro/astro#12689
can also confirm that this issue is happening with the following vite dynamic import functions from an integration hook ( const mod = await import(configPath) |
Maybe same as vitejs/vite#18962 |
I have a workaround, reading files with
|
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This issue is still present in [email protected]. |
The issue occurs in a custom astro plugin, when a dynamic import occurs. I get the following inside the
The line that triggers the error is: const cssRenamer = await import("postcss-rename").then((p) => p.default);
Downgrading to v4 solves the issue. Framework maintainers should pay attention to https://vite.dev/guide/api-environment-frameworks.html. Thanks |
Coming back with an update for the integration's standpoint... but i was able to get it working properly for resolving a user's config ( So this seems to be related to |
I ran into this issue in my website, too. When I was using notion-astro-loader to build my content layer collection with notion, the same error happened. I looked up the loader's repo and find the related code. It just uses the #fetchImage = async (imageFileObject) => {
try {
const fetchedImageData = await fileToImageAsset(imageFileObject);
this.#imagePaths.push(fetchedImageData.src);
return fetchedImageData.src;
}
catch (error) {
console.error(error)
this.#logger.error(`Failed to fetch image when rendering page.
Have you added \`image: { remotePatterns: [{ protocol: "https", hostname: "*.amazonaws.com" }] }\` to your Astro config file?\n
Error: ${getErrorMessage(error)}`);
// Fall back to using the remote URL directly.
return fileToUrl(imageFileObject);
}
};
/**
* Extract and locally cache the image from a file object.
* @see https://developers.notion.com/reference/file-object
*/
export async function fileToImageAsset(
file: FileObject,
): Promise<GetImageResult> {
return getImage({
src: fileToUrl(file),
inferSize: true,
});
}
export function fileToUrl(file: FileObject): string;
export function fileToUrl(file: FileObject | null): string | undefined;
export function fileToUrl(file: FileObject | null): string | undefined {
switch (file?.type) {
case "external":
return file.external.url;
case "file":
return file.file.url;
default:
return undefined;
}
} Here is the stack trace. It seems that it is caused by dynamic import, which is mentioned at a closed Vite issue.
|
Hey dude, I've found out the root cause of this issue. It seems that astro doesn't actually start a Vite server when handling content layer loader's syncing process. So, any calls for astro APIs are illegal since no Vite server can handle those 'virtual requests'. Checkout these codes:
The code lines above indicate that Vite server is only started for content collection initialization, and when it's time for layers to run their I've found out a stupid way to workaround this sh*t, but it causes memory leak. Just remove the Hopefully, I can find out the final way to solve this during my vacation haha. |
Astro Info
Describe the Bug
I read files to generate a content collection. Works fine during development, but fails during build with this output:
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
The text was updated successfully, but these errors were encountered: