Skip to content

Windows Error: Function called outside component initialization #460

@GrygrFlzr

Description

@GrygrFlzr

This is caused by Vite loading two separate svelte runtimes which causes things like setContext to fail. There is no workaround, as this requires a change in Vite's import normalization.


Describe the bug
Starting a new project using the main branch of kit results in an overlay error, and the component isn't interactive.

Logs
Browser console

[HMR][Svelte] Unrecoverable error in <Root>: next update will trigger a full reload

Overlay error

Failed to init component
<Root>
Error: Function called outside component initialization
    at get_current_component (http://localhost:3000/node_modules/.pnpm/svelte@3.35.0/node_modules/svelte/internal/index.mjs?v=66871719:649:15)
    at setContext (http://localhost:3000/node_modules/.pnpm/svelte@3.35.0/node_modules/svelte/internal/index.mjs?v=66871719:679:5)
    at instance (http://localhost:3000/.svelte/dev/generated/root.svelte?import:480:2)
    at init (http://localhost:3000/@fs/Users/GrygrFlzr/Documents/projects/sk-451/node_modules/.pnpm/svelte@3.35.0/node_modules/svelte/internal/index.mjs?v=66871719:1474:11)
    at new Root (http://localhost:3000/.svelte/dev/generated/root.svelte?import:574:3)
    at createProxiedComponent (http://localhost:3000/@fs/C:/Users/GrygrFlzr/Documents/projects/kit/node_modules/.pnpm/svelte-hmr@0.13.0-2_svelte@3.35.0/node_modules/svelte-hmr/runtime/svelte-hooks.js:245:9)
    at new ProxyComponent (http://localhost:3000/@fs/C:/Users/GrygrFlzr/Documents/projects/kit/node_modules/.pnpm/svelte-hmr@0.13.0-2_svelte@3.35.0/node_modules/svelte-hmr/runtime/proxy.js:240:20)
    at new Proxy<Root> (http://localhost:3000/@fs/C:/Users/GrygrFlzr/Documents/projects/kit/node_modules/.pnpm/svelte-hmr@0.13.0-2_svelte@3.35.0/node_modules/svelte-hmr/runtime/proxy.js:340:11)
    at Renderer.start (http://localhost:3000/.svelte/dev/runtime/internal/start.js:431:15)
    at async start (http://localhost:3000/.svelte/dev/runtime/internal/start.js:763:2)

To Reproduce
In the kit monorepo:

pnpm i
pnpm -r build

In another project folder:

npm init svelte@next
# no to typescript, use css

Point package.json's @sveltejs/kit to the path of the kit package:

{
  // ...
  "devDependencies": {
    "@sveltejs/kit": "file:~/Documents/projects/kit/packages/kit",
    // ...
  },
  // ...
}

Then install the dependencies and run dev:

pnpm i --shamefully-hoist
pnpm dev

Expected behavior
No errors

Information about your SvelteKit Installation:

@sveltejs/kit commit 055a822

  System:
    OS: Windows 10 10.0.19042
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
    Memory: 12.08 GB / 31.95 GB
  Binaries:
    Node: 14.15.3 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 7.6.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 88.0.4324.190
    Edge: Spartan (44.19041.423.0), Chromium (88.0.705.74)
    Internet Explorer: 11.0.19041.1
  npmPackages:
    @sveltejs/kit: file:~/Documents/projects/kit/packages/kit => 1.0.0-next.37
    svelte: ^3.29.0 => 3.35.0

Severity
Unusable.

Additional context
pnpm is required to support the monorepo linking.

I'm not entirely sure what's Windows-specific about this issue, but our CI seems to report success for the Ubuntu tests: https://github.com/sveltejs/kit/runs/2046784747

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions