Skip to content
Latchkey

Svelte "TypeError: store.subscribe is not a function" in CI

Svelte's $store syntax requires the value to follow the store contract (an object with a subscribe method). When a plain value or a wrong import is used as a store, the auto-subscription throws "subscribe is not a function" in tests or SSR.

What this error means

A component test or SSR render fails with "TypeError: X.subscribe is not a function", pointing at the auto-generated subscription code for a $-prefixed value.

node
TypeError: count.subscribe is not a function
    at create_fragment (src/lib/Counter.svelte:6:14)
    at init (svelte/internal)

Common causes

A non-store value used with $ syntax

You wrote $count but count is a plain number or object, not a store created with writable/readable, so it has no subscribe.

A wrong or default import of the store

Importing the module instead of the exported store, or a default vs named import mistake, yields a value without the store contract.

How to fix it

Create a real store

  1. Confirm the value is created with a Svelte store factory.
  2. Use $ only on values that implement subscribe.
  3. Re-run the test or build.
stores.js
import { writable } from 'svelte/store';
export const count = writable(0);

Fix the import shape

Import the named store export, not the module or a default that is not a store.

Component.svelte
import { count } from '$lib/stores.js';

How to prevent it

  • Only use $ on values that implement the store contract.
  • Export stores as named values and import them by name.
  • Cover stores with a component test so a bad store surfaces in CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →