svelteness / kit-docs

Documentation integration for SvelteKit.
https://kitdocs.vercel.app
MIT License
457 stars 32 forks source link

Function called outside component initialization error #59

Closed stephane-klein closed 1 year ago

stephane-klein commented 2 years ago

In this fresh KitDocs project, I have Function called outside component initialization error.

Here is how to reproduce:

$ git clone git@github.com:stephane-klein/kit-docs-playground.git
$ git checkout -b issue 474b05c80e26816a8c69799008abde67bf5e897f
$ cd kit-docs-playground/services/kit-docs
$ pnpm install
$ pnpm run dev

Go to http://127.0.0.1:3000/, I have this error:

$ pnpm run dev                                                                                                                       130

> mydocs@0.0.1 dev /home/stephane/git/github.com/stephane-klein/kit-docs-playground/services/kit-docs
> vite dev

  vite v2.9.14 dev server running at:

  > Local: http://localhost:3000/
  > Network: use `--host` to expose

  ready in 739ms.

Function called outside component initialization
Error: Function called outside component initialization
    at get_current_component (/node_modules/.pnpm/svelte@3.48.0/node_modules/svelte/internal/index.mjs:953:15)
    at Module.setContext (/node_modules/.pnpm/svelte@3.48.0/node_modules/svelte/internal/index.mjs:985:5)
    at root.svelte:15:1
    at $$render (/node_modules/.pnpm/svelte@3.48.0/node_modules/svelte/internal/index.mjs?v=8cb0458f:1755:22)
    at Object.render (/node_modules/.pnpm/svelte@3.48.0/node_modules/svelte/internal/index.mjs?v=8cb0458f:1763:26)
    at render_response (file:///home/stephane/git/github.com/stephane-klein/kit-docs-playground/services/kit-docs/.svelte-kit/runtime/server/index.js:1383:27)
    at async respond$1 (file:///home/stephane/git/github.com/stephane-klein/kit-docs-playground/services/kit-docs/.svelte-kit/runtime/server/index.js:2996:4)
    at async resolve (file:///home/stephane/git/github.com/stephane-klein/kit-docs-playground/services/kit-docs/.svelte-kit/runtime/server/index.js:3346:11)
    at async respond (file:///home/stephane/git/github.com/stephane-klein/kit-docs-playground/services/kit-docs/.svelte-kit/runtime/server/index.js:3290:20)
    at async file:///home/stephane/git/github.com/stephane-klein/kit-docs-playground/services/kit-docs/node_modules/.pnpm/@sveltejs+kit@1.0.0-next.370_svelte@3.48.0+vite@2.9.14/node_modules/@sveltejs/kit/dist/vite.js:2324:22
(node:494086) ExperimentalWarning: buffer.Blob is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Function called outside component initialization
Error: Function called outside component initialization
    at get_current_component (/node_modules/.pnpm/svelte@3.48.0/node_modules/svelte/internal/index.mjs:953:15)
    at Module.setContext (/node_modules/.pnpm/svelte@3.48.0/node_modules/svelte/internal/index.mjs:985:5)
    at root.svelte:15:1
    at $$render (/node_modules/.pnpm/svelte@3.48.0/node_modules/svelte/internal/index.mjs?v=8cb0458f:1755:22)
    at Object.render (/node_modules/.pnpm/svelte@3.48.0/node_modules/svelte/internal/index.mjs?v=8cb0458f:1763:26)
    at render_response (file:///home/stephane/git/github.com/stephane-klein/kit-docs-playground/services/kit-docs/.svelte-kit/runtime/server/index.js:1383:27)
    at async respond_with_error (file:///home/stephane/git/github.com/stephane-klein/kit-docs-playground/services/kit-docs/.svelte-kit/runtime/server/index.js:2758:10)
    at async respond$1 (file:///home/stephane/git/github.com/stephane-klein/kit-docs-playground/services/kit-docs/.svelte-kit/runtime/server/index.js:3013:4)
    at async resolve (file:///home/stephane/git/github.com/stephane-klein/kit-docs-playground/services/kit-docs/.svelte-kit/runtime/server/index.js:3346:11)
    at async respond (file:///home/stephane/git/github.com/stephane-klein/kit-docs-playground/services/kit-docs/.svelte-kit/runtime/server/index.js:3290:20)

Versions:

$ pnpm list
Legend: production dependency, optional only, dev only

mydocs@0.0.1 /home/stephane/git/github.com/stephane-klein/kit-docs-playground/services/kit-docs

dependencies:
@fontsource/fira-mono 4.5.0
cookie 0.4.1

devDependencies:
@iconify-json/ri 1.1.1                eslint 8.16.0                         shiki 0.10.1
@sveltejs/adapter-auto 1.0.0-next.57  eslint-config-prettier 8.3.0          svelte 3.48.0
@sveltejs/kit 1.0.0-next.370          eslint-plugin-svelte3 4.0.0           unplugin-icons 0.13.4
@svelteness/kit-docs 0.23.0           prettier 2.6.2                        vite 2.9.14
clsx 1.1.1                            prettier-plugin-svelte 2.7.0

Have you an idea to fix this error?

stephane-klein commented 2 years ago

I searched on thesvelte-kit Discord channel, I found that many people have this problem since 2022-07-13, I haven't found a solution yet.

stephane-klein commented 2 years ago

I see the solution here: https://discord.com/channels/457912077277855764/996789893369970699/996800417004527706

To fix the error, I need to upgrade from @sveltejs/kit 1.0.0-next.370 to @sveltejs/kit 1.0.0-next.371.

@mihar-22 I suggest to upgrade:

I will create a Pull Request.

stephane-klein commented 2 years ago

I found SvelteKit upstream issue about this subject: https://github.com/sveltejs/kit/issues/5495

stephane-klein commented 2 years ago

@mihar-22 what do you think about this Pull Request ? https://github.com/svelteness/kit-docs/pull/60

mihar-22 commented 1 year ago

Should be resolved now on latest.