Skip to content

@ogygia/jumpstart

External packages

jumpstart({ external }) keeps packages that can't be bundled outside the server bundle, imported from node_modules at run time. Each build prints one line naming every package that stayed outside, and why.

On this page

jumpstart() bundles every dependency into the server build. Most packages don’t mind. A few can’t work that way, and those go in external, by package name, the way Vite’s resolve.external takes them.

import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { jumpstart } from '@ogygia/jumpstart';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    ogygia(),
    jumpstart({
      external: ['sharp', '@acme/db']
    }),
    sveltekit()
  ]
});

When to list a package

List a package that:

  • has a native addon, a compiled .node file, such as sharp, @resvg/resvg-js (which social cards use) or a database driver;
  • reads files next to its own module, through new URL('./data.wasm', import.meta.url), __dirname or a path it builds from them. Bundled, its code moves into chunks/server.js and the file isn’t there any more;
  • must be one instance across the process, because two copies would each keep their own state.

A package that reads a file beside itself fails with an ENOENT naming the file when its code first runs. Since each module runs when it would without jumpstart() (Run order), that may be the first request to a page that imports it, not the build. The build names each such package for you (Files beside a module). Listing it in external fixes it.

A package in external is imported from node_modules at run time, so the deploy needs it installed. Keep it in your app’s dependencies.

Build line

At the end of each server build, jumpstart() prints one line that names every package the server still imports from node_modules, and why (jumpstart_external):

  • jumpstart({ external }): you listed it;
  • external in the Vite config: your config’s resolve.external or ssr.external keeps it out;
  • kept out by Vite or another plugin: something else made it external.

Node’s own modules and your app’s files aren’t counted. When nothing stayed outside, the line says so (jumpstart_external_none), so you can tell the plugin ran.

Each package on that line is one the deploy needs installed. A package you didn’t expect there, marked as kept out by Vite or another plugin, is worth a look: it’s read from node_modules file by file, as without jumpstart().

jumpstart: 2 outside the server bundle: @acme/db (jumpstart({ external })), sharp (jumpstart({ external }))

Files beside a module

A second line names each bundled package whose code reads a path beside its own module (jumpstart_file_beside). It looks for:

  • new URL('./x', import.meta.url);
  • join(__dirname, name);
  • the module’s folder, from import.meta.url, joined where it’s found or held in a variable and joined later;
  • import.meta.resolve('./x');
  • a createRequire require of a relative path.

Bundled, that read looks in the wrong folder, and fails only when the code runs, which may be the first request to a page, not the build. The build can’t tell whether the read really happens, so after the build, load a page that imports each named package once, and list in external the ones that fail.

Errors

A name listed twice is kept once.