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

Using getImage in content collection loader throwing error on build in Astro v5 #13053

Closed
1 task
An0nymusA opened this issue Jan 23, 2025 · 1 comment
Closed
1 task
Labels
needs triage Issue needs to be triaged

Comments

@An0nymusA
Copy link

Astro Info

Astro                    v5.1.8
Node                     v20.9.0
System                   Windows (x64)
Package Manager          npm
Output                   static
Adapter                  @astrojs/cloudflare
Integrations             copyStyles
                         generate-sitemap
                         generate-redirects
                         generate-favicons
                         copy-files
                         @astrojs/tailwind
                         @astrojs/preact
                         @playform/inline
                         @inox-tools/runtime-logger

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

I have a getImage function inside my content collection loader to optimize images found in the collection. It worked in v4, but after upgrading to v5 it stopped working and throws this errror when building. (For context when used outside the content config it works)

InvalidImageService: There was an error loading the configured image service. Please see the stack trace for more information.
    at eval (E:/Documents/LocalGarbage/bartender-headless/node_modules/astro/dist/assets/internal.js:24:21)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async getConfiguredImageService (E:/Documents/LocalGarbage/bartender-headless/node_modules/astro/dist/assets/internal.js:20:34)
    at async getImage (E:/Documents/LocalGarbage/bartender-headless/node_modules/astro/dist/assets/internal.js:54:19)
    at async getImage (astro:assets:27:42) {
  loc: undefined,
  title: 'Error while loading image service.',
  hint: undefined,
  frame: undefined,
  type: 'AstroError',
  cause: Error: Vite module runner has been closed.
      at SSRCompatModuleRunner.getModuleInformation (file:///E:/Documents/LocalGarbage/bartender-headless/node_modules/astro/node_modules/vite/dist/node/module-runner.js:1188:13)
      at SSRCompatModuleRunner.cachedModule (file:///E:/Documents/LocalGarbage/bartender-headless/node_modules/astro/node_modules/vite/dist/node/module-runner.js:1178:21)
      at request (file:///E:/Documents/LocalGarbage/bartender-headless/node_modules/astro/node_modules/vite/dist/node/module-runner.js:1214:99)
      at dynamicRequest (file:///E:/Documents/LocalGarbage/bartender-headless/node_modules/astro/node_modules/vite/dist/node/module-runner.js:1216:124)
      at getConfiguredImageService (E:/Documents/LocalGarbage/bartender-headless/node_modules/astro/dist/assets/internal.js:20:40)
      at getImage (E:/Documents/LocalGarbage/bartender-headless/node_modules/astro/dist/assets/internal.js:54:25)
      at getImage (astro:assets:27:82)
      at loader (E:/Documents/LocalGarbage/bartender-headless/src/content.config.ts:67:39)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async simpleLoader (file:///E:/Documents/LocalGarbage/bartender-headless/node_modules/astro/dist/content/content-layer.js:268:16)
      at async Promise.all (index 3)
      at async #doSync (file:///E:/Documents/LocalGarbage/bartender-headless/node_modules/astro/dist/content/content-layer.js:175:5)
      at async file:///E:/Documents/LocalGarbage/bartender-headless/node_modules/p-queue/dist/index.js:230:36
}

Example: https://stackblitz.com/edit/github-n5ufjfep?file=src%2Fcontent.config.ts

What's the expected result?

To get an optimized image

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-n5ufjfep

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 Jan 23, 2025
@An0nymusA An0nymusA changed the title Using getImage in content collection loader throwing error on build Using getImage in content collection loader throwing error on build in Astro v5 Jan 23, 2025
@ascorbic
Copy link
Contributor

I'm honestly a little surprised this ever worked! getImage was never expected to work in loaders, but it seems it does accidentally work in some scenarios. It's not that it was meant to be forbidden - it's not what it was designed for, and so is likely to cause problems even if it did work. Your best bet is to use getImage when you query the collection instead.

@ascorbic ascorbic closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

2 participants