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.

Error 'Function called outside component initialization' when calling route.meta()

See original GitHub issue

First of all, congrats for this amazing component.

I’m trying to get route information through route.meta() function inside an Svelte’s onMount(), but I’m getting the follow error message: Function called outside component initialization

I just tried to use example at https://github.com/AlexxNB/tinro/#route-meta in a fresh app, but without success.

I’ve added an example in REPL to show the problem (it’s the first page of Svelte quickstart template): https://svelte.dev/repl/9f8ca34b8aef4b6e88f1eb64c1eff27f?version=3.32.1

PS.: If I call route.meta() as is in the example, the message changes to Cannot read property 'meta' of undefined.

Anything I’m doing wrong? Or is it a bug?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
harvey-kcommented, Mar 31, 2021

@OysterD3

The solution mentioned here seemed to get router.goto working for me. Example vite.config.js:

export default defineConfig({ 
  optimizeDeps: {
    exclude: ['tinro']
  },
  plugins: [svelte()],
 ...
1reaction
renatodantascommented, Feb 3, 2021

That’s it. I was using a component outside an outer Route.

Thanks, @AlexxNB.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I get "Function called outside component initialization" when ...
After some debugging I found that error: Function called outside component initialization only happens on the dev server, on the client and ...
Read more >
Function called outside component initialization #592 - GitHub
This component is calling onMount, beforeUpdate, afterUpdate, or onDestroy. I tried moving onMount into a setTimeout & the same issue occurs.
Read more >
Router tutorial: tour of heroes - Angular
Define an array of routes, appRoutes , and pass them to the RouterModule.forRoot() method. The RouterModule.forRoot() method returns a module that contains ...
Read more >
Using a store outside of a component - Pinia
The easiest way to ensure this is always applied is to defer calls of useStore() by placing them inside functions that will always...
Read more >
Backbone.js
Note that calling model.off(), for example, will indeed remove all events on ... If you define an initialize function, it will be invoked...
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