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.
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
- Confirm the value is created with a Svelte store factory.
- Use
$only on values that implementsubscribe. - Re-run the test or build.
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.
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.