Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
`lifecycle_outside_component` error in rollup/rolldown SSR build | GoodFirstPicks

`lifecycle_outside_component` error in rollup/rolldown SSR build

sveltejs/svelte 3 comments 1mo ago
View on GitHub
mediumopenScope: somewhat clearSkill match: maybeSvelteTypeScript

Why this is a good first issue

Regression in SSR context handling requires understanding of Svelte's lifecycle and bundler integration.

AI Summary

A regression since Svelte 5.39.0 causes SSR builds with Rollup/Rolldown to throw lifecycle errors when using setContext. The issue appears related to context management during SSR rendering and requires investigation of the bundler integration. The maintainer comment suggests this involves shared globals between render and compiled code.

Issue Description

Describe the bug

Since [email protected], when building a component that uses setContext with Rolldown (or Rollup) for SSR, the build succeeds but the component throws a lifecycle_outside_component error at runtime. This error occurs when trying to render the component server-side with render from svelte/server.

This is a regression that started in Svelte 5.39.0 - downgrading to 5.38.0 resolves the issue.

This was probably introduced in #16748

Reproduction

repo: https://github.com/jackgdll/svelte-5-rolldown-ssr-error

  • install svelte@>=5.39.0
  • create a component that uses setContext
  • bundle it with Rollup or Rolldown
import { defineConfig } from "rolldown";
import svelte from "rollup-plugin-svelte";
import { sveltePreprocess } from "svelte-preprocess";

export default defineConfig({
  input: "src/main.svelte",
  output: {
    file: "dist/rolldown.js",
  },
  plugins: [
    svelte({
      compilerOptions: {
        generate: "server",
      },
      preprocess: sveltePreprocess(),
    }),
  ],
});
  • attempt to render the bundled output with render from svelte/server
  • lifecycle_outside_component error will be thrown

Logs

FAIL  test/ssr.test.js > SSR > renders Rolldown bundled component
Svelte error: lifecycle_outside_component
`setContext(...)` can only be used during component initialisation
https://svelte.dev/e/lifecycle_outside_component
 ❯ lifecycle_outside_component dist/rolldown.js:102:33
    100| function lifecycle_outside_component(name) {
    101|  if (dev_fallback_default) {
    102|   const error = /* @__PURE__ */ new Error(`lifecycle_outside_component\n\`${name}(...)\` can only be used during component initialisation\nhttps://svelte.dev/e/lifecycle_outside_component`);
       |                                 ^
    103|   error.name = "Svelte error";
    104|   throw error;
 ❯ get_or_init_context_map dist/rolldown.js:3405:28
 ❯ setContext dist/rolldown.js:3397:2
 ❯ dist/rolldown.js:

Want to work on this?

Claim this issue to let others know you're working on it. You'll earn 10 points when you complete it!

Risk Flags

  • regression
  • SSR-specific
  • context management
Loading labels...

Details

Points10 pts
Difficultymedium
Scopesomewhat clear
Skill Matchmaybe
Test Focusedno