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

Crashes on Astro when using an Image Service #617

Closed
okikio opened this issue Jan 26, 2024 · 0 comments
Closed

Crashes on Astro when using an Image Service #617

okikio opened this issue Jan 26, 2024 · 0 comments

Comments

@okikio
Copy link
Contributor

okikio commented Jan 26, 2024

Describe the bug

When you use a image service in Astro, a-la

import { defineConfig, squooshImageService } from 'astro/config';
import orama from "@orama/plugin-astro";

// https://astro.build/config
export default defineConfig({
  site: "https://astro.build",
  image: {
    service: squooshImageService()
  },
  output: "hybrid",
  integrations: [
    orama({
      // We can generate more than one DB, with different configurations
      mydb: {
        // Required. Only pages matching this path regex will be indexed
        pathMatcher: /.*/,

        // Optional. 'english' by default
        language: 'english',

        // Optional. ['body'] by default. Use it to constraint what is used to
        // index a page.
        contentSelectors: ['h1', 'main']
      }
    }),
  ],
});

The specific bug you get is this

...
ENOENT: no such file or directory, open 'undefineddist/about/index.html'
  Stack trace:
    at readFileSync (node:fs:456:20)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async withTakingALongTimeMsg (file:///workspace/astro/node_modules/.pnpm/astro@4.2.4_sass@1.70.0_typescript@5.3.3/node_modules/astro/dist/integrations/index.js:23:18)
    at async AstroBuilder.build (file:///workspace/astro/node_modules/.pnpm/astro@4.2.4_sass@1.70.0_typescript@5.3.3/node_modules/astro/dist/core/build/index.js:149:5)
    at async build (file:///workspace/astro/node_modules/.pnpm/astro@4.2.4_sass@1.70.0_typescript@5.3.3/node_modules/astro/dist/core/build/index.js:47:3)
    at async runCommand (file:///workspace/astro/node_modules/.pnpm/astro@4.2.4_sass@1.70.0_typescript@5.3.3/node_modules/astro/dist/cli/index.js:127:7)

I've reduced the issue to be due to the ways Orama selects the base URL for the built HTML files when analyzing, in fact I find the approach kind of odd since Astro now supports the baseURL directly via dir, I'm assuming this was due to an older version of Astro.

The way the Astro orama plugin currently selects the baseURL is basically to look through all the routes of the build including endpoint routes (which do NOT have a destination URL), the orama plugin then selects the first route and checks the destination URL, but Astro automatically pushes the image endpoint routes to being the first route when using an image service, which messes up the baseURL Orama uses, thus the fix is to just rely on Astro to give us the baseURL.

The solution for this issue is to just use the baseURL Astro provides in the astro:build:done hook like so const basePath = dir.pathname.slice(isWindows ? 1 : 0);

Hopefully, this helps https://docs.astro.build/en/reference/integrations-reference/#hooks:~:text=%27-,astro%3Abuild%3Adone%27%3F%3A%20(options%3A%20%7B%20dir%3A%20URL,-%3B%20routes%3A%20RouteData%5B%5D%3B%20logger

To Reproduce

  1. Install Astro & the Astro Orama Plugin
  2. Use an image service
  3. Error when running astro build

Expected behavior

I expected the correct baseURL should've been used

Environment Info

OS: Ubuntu 22.04
Node: 21
@orama/plugin-astro: 2.0.2

Affected areas

Data Insertion, Environment/OS

Additional context

This is a small bug in the way orama determines the baseURL when used in Astro. I'll create a quick PR and add it to the issue.

PR #618

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant