Function called outside component initialization from brand new SvelteKit installation

Viewed 313

When I create a new Svelte App as explained in the doc https://kit.svelte.dev/docs/introduction#getting-started , I'm doing:

npm create svelte my-app
cd my-app
npm install
npm run dev

Then when I go to http://localhost:3000

I go the following error, while I didn't do anything yet..

Function called outside component initialization
Error: Function called outside component initialization
    at get_current_component (/node_modules/svelte/internal/index.mjs:953:15)
    at Module.setContext (/node_modules/svelte/internal/index.mjs:985:5)
    at root.svelte:14:1

Here is the packaga.json I have:

{
    "name": "dapp",
    "version": "0.0.1",
    "scripts": {
        "dev": "vite dev",
        "build": "vite build",
        "package": "svelte-kit package",
        "preview": "vite preview",
        "prepare": "svelte-kit sync"
    },
    "devDependencies": {
        "@sveltejs/adapter-auto": "next",
        "@sveltejs/kit": "next",
        "svelte": "^3.46.0",
        "vite": "^2.9.13"
    },
    "type": "module",
    "dependencies": {
        "@fontsource/fira-mono": "^4.5.0",
        "cookie": "^0.4.1"
    }
}

Most likely, it is related with the new version using "vite", but I have absolutely no idea on how to solve this...

1 Answers

I just had this problem, and it happens that the version of vite is outdated.

I fixed the problem by updating vite to the latest version:

yarn upgrade vite --latest
Related