SvelteKit - Function called outside component initialization
See original GitHub issueHi
I’m trying to use sswr with a newly created SvelteKit project, building with the node
adapter.
I have added some simple test after having had issues:
import { useSWR } from 'sswr';
try {
const { data } = useSWR('http://jsonplaceholder.typicode.com/posts/1');
} catch(e) {
console.log(e);
}
test to a
- route
- component
and I always get back the same error:
Error: Function called outside component initialization
at get_current_component (index.mjs:813)
at onMount (index.mjs:820)
at l.useSvelte (index.js:1)
at useSWR (index.js:1)
at instance ([dialogId].svelte:42)
at init (index.mjs?v=99bae134:1660)
at new U5BdialogIdu5D ([dialogId].svelte:153)
at createComponent (svelte-hooks.js:136)
at U5BdialogIdu5D.targetCmp.$replace (svelte-hooks.js:183)
at refreshComponent (proxy.js:170)
Any idea why that might be?
Issue Analytics
- State:
- Created 2 years ago
- Comments:15 (13 by maintainers)
Top Results From Across the Web
Function called outside component initialization - Stack Overflow
i wanna to recall the onMount in my Svelte app by clicking some button, but i got this error. Any idea would be...
Read more >Function called outside component initialization #592 - GitHub
I'm getting a Function called outside component initialization error from a sapper v0.26.0-alpha.10 project. A component is being loaded ...
Read more >Svelte - Function called outside component initialization from ...
Hi there, I have got a very weird behaviour when I'm creating new Sveltekit app. As explained in the doc…
Read more >How to fix "Function called outside component initialization ...
But when I moved svelte to a dependency I got an error saying Function called outside component initialization . This is documented on...
Read more >Function called outside component initialization - CodeSandbox
urql svelte, error: Function called outside component initialization. 0. Embed Fork Create Sandbox Sign in. Sandbox Info. urql svelte, error: Function ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s not a bug in this package, but in
sveltekit
. I saw the same problem on my own tinkering withreact-query
- so I opened a bug insveltekit
. See https://github.com/sveltejs/kit/issues/2147.Btw, it only happens when both preconditions are true: a) lifecycle-method called inside an installed package. b) in dev-mode.
It works in svelte-repl though. So its likely a problem with the vite-dev-server.
PS: You can circumvent the bug for now by installing
swrev
and copy sswr to your local $lib-folder and import it from there.That could explain why my local symlinked pkg was working lol