Skip to content

App breaks, when endpoint marked with 'export const prerender = true' is not linked #11982

Closed
@salty-muffin

Description

@salty-muffin

Describe the bug

I have a situation where the content on a static site is determined by markdown files. These markdown files may include images by referencing an endpoint that automatically creates optimized images. This endpoint is marked to prerender. Because I don't manage the content (it will be managed with a git-based CMS by other people), there may be cases where no images are referenced in any markdown file. In this case, the build fails.

I have tested this with adapter-static, adapter-node and adapter-auto. Setting strict: false for adapter-static does not fix it.

I don't think I am doing anything that I shouldn't. It seems reasonable to prerender an endpoint that does image optimization when the content doesn't change after building. Of course, removing the endpoint, when no images are linked in any markdown file, would fix it, but I obviously cannot expect people who manage the content to do this.

The closest past issue I found is this: #7183, but it does not seem to be my situation exactly.

Reproduction

https://github.com/salty-muffin/sveltekit-decapcms/tree/reproduction

Install dependencies with npm i and then build with npm run build.

Uncommenting # image: /images/demo-image.jpg in src/content/posts/demo-page.md allows the build to work.

The endpoint in question can be found at src/routes/images/[slug].[type]@[query].[ending]/+server.ts.

I tried to remove everything unnecessary from the repo and I hope it is clear enough.

Logs

node:internal/event_target:1100
  process.nextTick(() => { throw err; });
                           ^
Error: The following routes were marked as prerenderable, but were not prerendered because they were not found while crawling your app:
  - /images/[slug].[type]@[query].[ending]

See https://kit.svelte.dev/docs/page-options#prerender-troubleshooting for info on how to solve this
    at prerender (file:///home/flounder/git/sveltekit-decapcms/node_modules/@sveltejs/kit/src/core/postbuild/prerender.js:495:9)
    at async MessagePort.<anonymous> (file:///home/flounder/git/sveltekit-decapcms/node_modules/@sveltejs/kit/src/utils/fork.js:22:16)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:326:10)
    at [kOnMessage] (node:internal/worker:337:37)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:826:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)

Node.js v20.11.1

System Info

System:
    OS: Linux 6.5 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (4) x64 Intel(R) Core(TM) m3-8100Y CPU @ 1.10GHz
    Memory: 1.67 GB / 7.62 GB
    Container: Yes
    Shell: 3.3.1 - /usr/bin/fish
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v20.11.1/bin/npm
  npmPackages:
    @sveltejs/adapter-static: ^3.0.0 => 3.0.1 
    @sveltejs/kit: ^2.0.0 => 2.5.1 
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.0.2 
    svelte: ^4.2.7 => 4.2.11 
    vite: ^5.0.3 => 5.1.4

Severity

serious, but I can work around it

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions