pateketrueke / yrv

Your routing vibes! (for Svelte)
https://svelte.dev/repl/0f07c6134b16432591a9a3a0095a80de
161 stars 9 forks source link

Uncaught Error #51

Closed jhechtf closed 4 years ago

jhechtf commented 4 years ago

YRV Version: 0.0.30

Going to a project i haven't touched in awhile, starting the dev server up I now get this error.

Uncaught TypeError: Object(...) is not a function
    at eval (Router.svelte:280)
    at run (index.mjs:167)
    at Array.map (<anonymous>)
    at eval (index.mjs:1525)
    at flush (index.mjs:861)
    at init (index.mjs:1611)
    at new Main (main.svelte:133)
    at eval (main.js:8)
    at Module../src/main.js (dashboard.9635fb5645339333ce10.js:823)
    at __webpack_require__ (dashboard.9635fb5645339333ce10.js:64)

Which is caused by the following code

<script>
import {Router, Route} from "yrv";
</script>
<Router>
  <Route exact path="/" component={() => import('./routes/main.svelte')} />
</Router>

If I remove the Route component the error goes away, but obviously this is not optimal.

pateketrueke commented 4 years ago

Try just passing the import(...) without the arrow function, I think yrv is trying to evaluate the given value, see how is that implemented: https://github.com/pateketrueke/yrv/blob/master/src/lib/Route.svelte#L82-L98

jhechtf commented 4 years ago

It's the same usage as the following, from the README

<Route exact path="/lazy" component="{() => import('path/to/another-component.svelte')}"/>
jhechtf commented 4 years ago

Out of posterity's sake I tried it without the arrow function, gives the same error. Also unless I am mistaken https://github.com/pateketrueke/yrv/blob/master/src/lib/Route.svelte#L92-L98 handle the original use case.

pateketrueke commented 4 years ago

Yeah, it looks weird to me because it should work as is, can you share more of the code you're using?

More importantly is the setup you've been using for this, it should allow dynamic-import calls.

jhechtf commented 4 years ago

That's literally it on the current project. I was just trying to get the skeleton setup so I could push it to a repo for another developer to use.

After my previous comment I decided to test on an older version of yrv in a project that was more complex, but that I knew for a fact was working previously and I ran into the same thing. Thisleads me to believe this might not be an error relating to yrv at all, and is instead an error with a newer svelte version. I had to stop my investigation before I could determine what version of svelte was being used for the new project, but I have yrv version 0.0.30 being used in another project, but when running the install had it freeze the lockfile and only install those versions. So far, the combination of Svelte 3.20.1 and YRV 0.0.30 seems the winning combination. I'll double check what version the other project is using and comment back what I find.

pateketrueke commented 4 years ago

Interesting, let me see if rebuilding yrv with the latest svelte version could fix this up. 🤔

jhechtf commented 4 years ago

To further confuse matters, I tried simply setting up svelte + yrv + webpack in a new directory and it worked just fine. I'm unsure what could possibly be causing an error in the project I'm using.

pateketrueke commented 4 years ago

May the lock-file introduce this behavior? Try removing it from your previous project and npm i then.

jhechtf commented 4 years ago

I thought that too at some point and had just full nuked the lock file at least twice in the other project. I'm honestly voting to close -- I'm not sure what variety of shenanigans I did, but I think this is specific to me. Unless someone else runs across this as well, I can't place why it's happening.