How can I fix this error when trying to deploy my svelte app on github pages?

Viewed 666

I am trying to deploy my svelte app on GitHub Pages and cannot get rid of these errors I get from running 'npm run build'.

The exact errors are:

(node:15364) ExperimentalWarning: buffer.Blob is an experimental feature. This feature could change at any time
file:///C:/Isabella/personal-website/node_modules/@sveltejs/kit/dist/prerender.js:460
                                throw new Error(format_error(details, config));
                                  ^
Error: 404 /src/images/github.png (linked from /)
    at file:///C:/Isabella/personal-website/node_modules/@sveltejs/kit/dist/prerender.js:460:11
    at save (file:///C:/Isabella/personal-website/node_modules/@sveltejs/kit/dist/prerender.js:744:4)
    at visit (file:///C:/Isabella/personal-website/node_modules/@sveltejs/kit/dist/prerender.js:635:3)
[vite-plugin-svelte-kit] Prerendering failed with code 1
error during build:
Error: Prerendering failed with code 1
    at ChildProcess.<anonymous> (file:///C:/Isabella/personal-website/node_modules/@sveltejs/kit/dist/vite.js:2367:14)
    at ChildProcess.emit (node:events:527:28)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)

And here is my svelte.config.js file:

import preprocess from 'svelte-preprocess';
import adapter from '@sveltejs/adapter-static';

/** @type {import('@sveltejs/kit').Config} */
const config = {
  preprocess: preprocess(),
    kit: {
        // target: '#svelte',
        adapter: adapter({
            pages: 'build',  // path to public directory
            assets: 'build',  // path to public directory
            fallback: null,
        }),
        prerender: {
            // This can be false if you're using a fallback (i.e. SPA mode)
            default: true
          }
    }
};

export default config;
1 Answers

The issue is that you're linking to /src/images/github.png in index.svelte but the prerenderer can't find the file because it tries to look for the file in the default assets folder static.

To fix it change the link to the correct path and put the image in the static folder (i.e. images/github.png if you put the images folder in the static folder).

Related