Circular dependencies throw error 500
See original GitHub issueDescribe the bug SvelteKit throws an error when using components with circular dependencies. Repository was created with commands shown on SK homepage and almost nothing was changed. I only included components from REPL.
Logs Console
Circular dependency: path/to/repo/src/routes/index.svelte -> /src/lib/App.svelte -> /src/lib/Structure.svelte -> /src/lib/C.svelte -> /src/lib/Structure.svelte
To Reproduce
I created repo with the problem here https://github.com/lukeeno/recursive-sveltekit
and also REPL with basically the same code, but in REPL it works https://svelte.dev/repl/c90b530e67c94b8995bf4bb5b7f70d3b?version=3.35.0
Expected behavior Not throwing error and recursively render components as shown in REPL
Stacktraces
Browser message
500
Cannot read property 'default' of null
TypeError: Cannot read property 'default' of null
at path/to/repo/src/lib/C.svelte:7:22
at Object.$$render (path/to/repo/node_modules/svelte/internal/index.js:1369:22)
at eval (/src/lib/Structure.svelte:18:197)
at Proxy.each (path/to/repo/node_modules/svelte/internal/index.js:1335:16)
at path/to/repo/src/lib/Structure.svelte:15:7
at Object.$$render (path/to/repo/node_modules/svelte/internal/index.js:1369:22)
at eval (/src/lib/App.svelte:21:97)
at Object.$$render (path/to/repo/node_modules/svelte/internal/index.js:1369:22)
at eval (path/to/repo/src/routes/index.svelte:11:91)
at Object.$$render (path/to/repo/node_modules/svelte/internal/index.js:1369:22)
Information about your SvelteKit Installation:
- The output of
npx envinfo --system --npmPackages svelte,@sveltejs/kit --binaries --browsers
System:
OS: Linux 5.9 Manjaro Linux
CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
Memory: 1.29 GB / 15.34 GB
Container: Yes
Shell: 5.8 - /bin/zsh
Binaries:
Node: 14.16.0 - /usr/bin/node
npm: 7.6.3 - /usr/bin/npm
Browsers:
Brave Browser: unknown
Firefox: 86.0.1
npmPackages:
@sveltejs/kit: next => 1.0.0-next.60
svelte: ^3.29.0 => 3.35.0
-
Your browser Brave Version 1.20.103 Chromium: 88.0.4324.152 (Official Build) unknown (64-bit)
-
Your adapter Node
Severity
Really severe if you need circular dependencies, but apart from that it’s okay
Additional context
Is there any workaround with async component loading?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
Fix just landed in Vite: https://github.com/vitejs/vite/pull/3950 @Rich-Harris
I guess this is a Vite issue. It’s definitely solvable — SvelteKit used to have an SSR runtime that handled this case, but we removed it because Vite implemented something very similar — though I can’t speak to how straightforward it would be to add it to Vite. Looks like there’s a couple of related issues already, e.g. https://github.com/vitejs/vite/issues/2258