Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vite gives "Error: Function called outside component initialization" when used with Routify, only in Dev Build Mode #2647

Closed
3 tasks done
derpycoder opened this issue Mar 23, 2021 · 10 comments

Comments

@derpycoder
Copy link

derpycoder commented Mar 23, 2021

⚠️ 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. 🙃

@meteorlxy
Copy link
Contributor

Seems that your reproduce repo is invalid:

Failed to resolve import "../.routify/routes" from "src/App.svelte". Does the file exist?

@derpycoder
Copy link
Author

@meteorlxy,

The file gets created upon using npm run dev:routify.

or npm run routify separately and then doing npm run dev.

@meteorlxy
Copy link
Contributor

image

Seems it work well here 🤔 Where is the error message?

@derpycoder
Copy link
Author

Production build works great, but the dev build fails.

@derpycoder
Copy link
Author

image

@derpycoder
Copy link
Author

P.S. I moved the problem code to another branch, so that I can use the working part of the repo.

Branch: vite-routify-issue.

@derpycoder
Copy link
Author

derpycoder commented Mar 24, 2021

Hey the issue was because of a space in parent folder name.

Svelte Kit Issue Resolution

@Shinigami92
Copy link
Member

@abhijit-kar So is it solved? Should I close this issue?

@patak-dev
Copy link
Member

This issue is tracked here #2585, and there is a PR already to fix it

@derpycoder
Copy link
Author

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.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants