Skip to content

Svelte 5: getContext is undefined. #12710

Closed as not planned
Closed as not planned
@HighFunctioningSociopathSH

Description

Describe the bug

Since the last update (svelte@5.0.0-next.206), svelte throws an error saying getContext is undefined if getContext was called in a svelte.ts file. works fine in next.205

Reproduction

test.svelte.ts

import { getContext } from "svelte";

export function fetchContext() {
  const test = getContext("something");

  return test;
}

Child.svelte

<script lang="ts">
  import { fetchContext } from "./test.svelte";

  const result = fetchContext();
</script>

Logs

client.js?v=731e5348:299 Uncaught (in promise) 
ReferenceError: getContext is not defined
    at fetchContext (test.svelte.ts:4:16)
    at Child (Child.svelte:4:18)
    at chunk-KRQXFADS.js?v=731e5348:209:58
    at update_reaction (chunk-IUDHG5ZN.js?v=731e5348:1093:23)
    at update_effect (chunk-IUDHG5ZN.js?v=731e5348:1213:21)
    at create_effect (chunk-IUDHG5ZN.js?v=731e5348:274:7)
    at branch (chunk-IUDHG5ZN.js?v=731e5348:398:10)
    at chunk-KRQXFADS.js?v=731e5348:202:17
    at update_reaction (chunk-IUDHG5ZN.js?v=731e5348:1093:23)
    at :5174/update_effect …text is not defined
    at fetchContext (test.svelte.ts:4:16)
    at Child (Child.svelte:4:18)
    at chunk-KRQXFADS.js?v=731e5348:209:58
    at update_reaction (chunk-IUDHG5ZN.js?v=731e5348:1093:23)
    at update_effect (chunk-IUDHG5ZN.js?v=731e5348:1213:21)
    at create_effect (chunk-IUDHG5ZN.js?v=731e5348:274:7)
    at branch (chunk-IUDHG5ZN.js?v=731e5348:398:10)
    at chunk-KRQXFADS.js?v=731e5348:202:17
    at update_reaction (chunk-IUDHG5ZN.js?v=731e5348:1093:23)
    at update_effect (chunk-IUDHG5ZN.js?v=731e5348:1213:21)

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-12650H
    Memory: 4.54 GB / 15.63 GB
  Binaries:
    Node: 20.12.2 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
    bun: 1.1.3 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (126.0.2592.102)
    Internet Explorer: 11.0.22621.3527

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions