question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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.

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 & then npm run serve (It will work)
  • Run Dev Build with npm run dev:routify (It will fail).

no-work

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:closed
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
derpycodercommented, Mar 25, 2021

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.

2reactions
patak-devcommented, Mar 24, 2021

This issue is tracked here https://github.com/vitejs/vite/issues/2585, and there is a PR already to fix it

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found