Vite gives "Error: Function called outside component initialization" when used with Routify, only in Dev Build Mode
See original GitHub issue⚠️ IMPORTANT ⚠️ Please do not ignore this template. If you do, your issue will be closed immediately.
- Read the docs.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- This is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
Describe the bug
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.
Reproduction
Problem Repo: vite-routify-issue branch
- Run Prod Build with
npm run build
& thennpm run serve
(It will work) - Run Dev Build with
npm run dev:routify
(It will fail).
System Info
vite
version: 2.1.0- Operating System: Zorin OS - Ubuntu
- Node version: v14.16.0
- Package manager (npm/yarn/pnpm) and version: pnpm (5.18.8)
P.S. I am going to write a blog post about Vite + Routify in my blog Derpy Coder and replace my Rollup based dev env. So I need this to work. 🙃
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Function called outside component initialization from brand ...
I just had this problem, and it happens that the version of vite is outdated. I fixed the problem by updating vite to...
Read more >How to fix "Function called outside component initialization ...
Recently, a sapper-based project went over the limit for the size of the built image sent to the cloud platform we were using....
Read more >svelte-navigator - npm Package Health Analysis - Snyk
I'm using Vite. Why am I getting errors with svelte-navigator ? Vite tries to optimize the dependencies of your app. Unfortunately, this process...
Read more >Error: Function called outside component initialization using Vite
I am trying to use the router as mentioned in the README.md but I am unable to do so with Vite. I searched...
Read more >Svelte Add: Easily & integrations & Other Functionality to Svelte Apps
The preferred way to add integrations to a Vite-powered Svelte app is to start ... When I'm only using a single function from...
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
Adding routify, urql, & having space in folder caused the issue.
So after going through several reddit threads, git issues, I deduced that:
Removing space in enclosing folder of the project & Adding this to the vite.config.js.
optimizeDeps: { exclude: ["@roxi/routify", "@urql/svelte"] },
Solves the issue.
This issue is tracked here https://github.com/vitejs/vite/issues/2585, and there is a PR already to fix it