SvelteKit Guide

Looking for guidance on deploying a SvelteKit app: https://kit.svelte.dev

Tried the normal node instructions, but keep getting errors:

“Failed due to unhealthy allocations”

If you run fly logs after a failed SvelteKit deploy, you might be able to see why it isn’t working. “Unhealthy Allocations” either means the process crashed or health checks failed.

From that repository, I’m guessing it can’t figure out the start command. How do you actually run a SvelteKit app? If you add a start script in package.json that runs what you want, it might work.

1 Like

You need to add a start to the package.json with the following command node build/index.js. But do remember you will need some other steps before this to run the build command. I’m using a Dockerfile to action those steps first.

"scripts": {
    "dev": "svelte-kit dev",
    "build": "svelte-kit build",
    "preview": "svelte-kit preview",
    "start": "node build/index.js"
}

and did you solve this?

I would be very interested to have such guide !

It would be pretty cool if there was a svelte-kit adapter like there is for Vercel. Might get a lot people here on fly.
If anyone builds one, I’m keen to hear about it.

1 Like

I’m using a docker image to deploy my SvelteKit application with pnpm on Fly.io.

You can trigger the deploy with this command:

fly deploy --config fly.toml --dockerfile Dockerfile

And the Dockerfile looks like this:

# This dockerfile must be built with the monorepo root directory as cwd
FROM node:lts-alpine

RUN npm i -g pnpm@latest

# all files needed for the build
COPY package.json .
COPY pnpm-lock.yaml .
COPY tsconfig.json .
COPY svelte.config.js .
COPY vite.config.ts .

# all folders needed for the build
COPY src src/

RUN pnpm install --frozen-lockfile

RUN pnpm build

EXPOSE 8080

CMD ["node", "build"]
1 Like

Fly doesn’t really need an adapter in the way that vercel does, just building your app for node.js will work perfectly. Vercel needs it because of it’s own special APIs, but fly just runs linux vms.

If you want to get sveltekit going on fly, you just need a Dockerfile that runs npm run start and you are set

Here is a Dockerfile for SvelteKit

Hello guys, I put together a video showing how to (easily) dockerize and deploy a SvelteKit app. I am hoping to partner with Fly.io to do a whole series, but thought you might find this helpful! Deploying an App to Fly.io | SvelteKit example app Dockerize and launch! - YouTube

Have a great day!
Mitch -Consulting Ninja

1 Like