Deploying a SvelteKit application to Heroku

— 1 minute read

I've been a fan of Svelte for a few years now, so I'm very excited about SvelteKit.

I've begun migrating an existing Node + Express project that's hosted on Heroku to SvelteKit, and I couldn't find any clear instructions about how to make the deployment work using SvelteKit's Node adapter.

At first I encountered an error about svelte-kit not being found. This turned out to be Heroku helpfully pruning devDependencies, which removes @sveltejs/kit from the built application. I disabled this behaviour by setting the NPM_CONFIG_PRODUCTION variable to false:

$ heroku config:set NPM_CONFIG_PRODUCTION=false

Then, while the app deployed successfully, it kept crashing with an R10 error shortly after launch. It turns out that the Procfile must be set to the following (assuming that your start script runs svelte-kit start):

web: npm run start -- --port $PORT --host 0.0.0.0

I hope this is helpful for anyone else trying to achieve the same thing.