-
Notifications
You must be signed in to change notification settings - Fork 86
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
Routify gives "Error: Function called outside component initialization" when used with Vite, only in Dev Build Mode #353
Comments
Hey the issue was because of a space in parent folder name. |
Happy you got it fixed @abhijit-kar ! |
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
To recreate the issue. |
You can try this repo https://github.com/roxiness/routify-templates It should be able to give you a working vite template. |
Hey @jakobrosenberg, I initialized the starter repo directly from a working Svelte template. However adding routify, urql, & having space in folder caused the issue. So after going through several reddit threads, git issues, I deduced that:
Solves the issue. |
Ah yes. You can see how we build the vite template here: |
Damn, I am going to copy so many configs from that blueprint. Thanks. |
I feel like 'optimizeDeps: { exclude: ["@roxi/routify", "@urql/svelte"] },' needs to be included somewhere in the docs for users of Vite, because this was driving me absolutely mad. Thanks for suggesting it @abhijit-kar! |
Yea, at least the top of the urql-svelte docs mention it now. Unfortunately, adding Could you possible share a working implementation? Perhaps my client initialization is in the wrong file or something. It seems like this is mostly due to urql client using |
@drannex42 @fractalhq what would be the best place for Vite documentation? FAQ or a dedicated section? |
My vote would be dedicated. I imagine it will be the de facto bundler for most users. |
Agreed with @fractalhq, should be a dedicated section. Re: url1 - I just took a look, and while I thought I had urlq as a dep, I don't. I just needed to add @roxi/routify to my exclude. Here is my vite.config.js if it helps:
A lot of that isn't needed, but that's my projects config file. |
This doesn't seem to work if you're using transitions. It throws the following error:
Might be a problem with vite-plugin-svelte judging from the output:
|
what version of vite-plugin-svelte @agrear |
I also tried earlier versions up to |
Replacing |
bug 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.
`
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 (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) `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 (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. 🙃
The text was updated successfully, but these errors were encountered: