Routify gives "Error: Function called outside component initialization" when used with Vite, only in Dev Build Mode
See original GitHub issuebug description I love Routify, and am able to use it with Rollup without issues. See: Quiller Bee & Quiller Bee Repo.
However, since Rollup is slow, I decided to use Vite.
After integrating Routify, the production build works great, but the Dev build gives error. See Vitte Repo: vite-routify-issue branch. And I really need the speed of dev build with Vite & especially the HMR support.
` <Router> 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=f03f2977:649:15) at setContext (http://localhost:3000/node_modules/.pnpm/svelte@3.35.0/node_modules/svelte/internal/index.mjs?v=f03f2977:679:5) at instance (http://localhost:3000/node_modules/.pnpm/@roxi/routify@2.15.1/node_modules/@roxi/routify/runtime/Router.svelte?import:176:2) at init (http://localhost:3000/home/abhijit/Documents/Experiments/QuillerBee/Sub Experiments/vitte/node_modules/.pnpm/svelte@3.35.0/node_modules/svelte/internal/index.mjs?v=f03f2977:1474:11) at new Router (http://localhost:3000/node_modules/.pnpm/@roxi/routify@2.15.1/node_modules/@roxi/routify/runtime/Router.svelte?import:264:3) at createProxiedComponent (http://localhost:3000/node_modules/.pnpm/svelte-hmr@0.13.3_svelte@3.35.0/node_modules/svelte-hmr/runtime/svelte-hooks.js:245:9) at new ProxyComponent (http://localhost:3000/node_modules/.pnpm/svelte-hmr@0.13.3_svelte@3.35.0/node_modules/svelte-hmr/runtime/proxy.js:240:20) at new Proxy<Router> (http://localhost:3000/node_modules/.pnpm/svelte-hmr@0.13.3_svelte@3.35.0/node_modules/svelte-hmr/runtime/proxy.js:340:11) at create_fragment (http://localhost:3000/src/App.svelte?import:26:11) at init (http://localhost:3000/home/abhijit/Documents/Experiments/QuillerBee/Sub Experiments/vitte/node_modules/.pnpm/svelte@3.35.0/node_modules/svelte/internal/index.mjs?v=f03f2977:1489:37)
<App> 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=f03f2977:649:15) at setContext (http://localhost:3000/node_modules/.pnpm/svelte@3.35.0/node_modules/svelte/internal/index.mjs?v=f03f2977:679:5) at instance (http://localhost:3000/node_modules/.pnpm/@roxi/routify@2.15.1/node_modules/@roxi/routify/runtime/Router.svelte?import:176:2) at init (http://localhost:3000/home/abhijit/Documents/Experiments/QuillerBee/Sub%20Experiments/vitte/node_modules/.pnpm/svelte@3.35.0/node_modules/svelte/internal/index.mjs?v=f03f2977:1474:11) at new Router (http://localhost:3000/node_modules/.pnpm/@roxi/routify@2.15.1/node_modules/@roxi/routify/runtime/Router.svelte?import:264:3) at createProxiedComponent (http://localhost:3000/node_modules/.pnpm/svelte-hmr@0.13.3_svelte@3.35.0/node_modules/svelte-hmr/runtime/svelte-hooks.js:245:9) at new ProxyComponent (http://localhost:3000/node_modules/.pnpm/svelte-hmr@0.13.3_svelte@3.35.0/node_modules/svelte-hmr/runtime/proxy.js:240:20) at new Proxy<Router> (http://localhost:3000/node_modules/.pnpm/svelte-hmr@0.13.3_svelte@3.35.0/node_modules/svelte-hmr/runtime/proxy.js:340:11) at create_fragment (http://localhost:3000/src/App.svelte?import:26:11) at init (http://localhost:3000/home/abhijit/Documents/Experiments/QuillerBee/Sub%20Experiments/vitte/node_modules/.pnpm/svelte@3.35.0/node_modules/svelte/internal/index.mjs?v=f03f2977:1489:37) `package.json
"scripts": { "dev": "vite", "routify": "routify", "dev:routify": "run-p dev routify", "fix": "pnpx eslint --fix \"{,!(node_modules|public|dist|.routify)/**/}*.{js,svelte}\"", "format": "pnpx prettier --write --plugin-search-dir=. \"{,!(node_modules|public|dist|.routify)/**/}*.{js,svelte,json}\"", "prebuild": "test \"$CI\" = true && npx pnpm install --store=node_modules/.pnpm-store || echo skiping pnpm install", "build": "routify -b && vite build", "serve": "vite preview" },
version
“@roxi/routify”: “^2.15.1”,
“svelte”: “^3.35.0”,
“vite”: “^2.1.0”,
screenshot
P.S. I am going to write a blog post about Vite + Routify combo in my blog DerpyCoder and also use it to replace my Rollup based Dev env. So I need this to work. 🙃
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (7 by maintainers)
Ah yes. You can see how we build the vite template here:
https://github.com/roxiness/routify-templates/blob/5b1e3bdcb347a273a7e596cc5c42afd0c0661b1b/fragments/svite/blueprint.js#L17-L37
@jakobrosenberg,
After the success of my repo, where I experimented with Vite + Routify.
I integrated vite with my project. It gave the same error, even though there is no space in any enclosing folder.
See: Quiller Bee - vitte branch
npm run routify
npm run dev
To recreate the issue.