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

Could not get page props for route "home" #16

Closed
subhendukundu opened this issue Apr 11, 2021 · 6 comments
Closed

Could not get page props for route "home" #16

subhendukundu opened this issue Apr 11, 2021 · 6 comments

Comments

@subhendukundu
Copy link

Could not get page props for route "home"
FetchError: invalid json response body at http://localhost:3000/props/login?propsGetter=%2Fprops%2Fhome&data=%257B%2522name%2522%253A%2522home%2522%252C%2522path%2522%253A%2522%252F%2522%252C%2522fullPath%2522%253A%2522%252Flogin%2522%252C%2522query%2522%253A%257B%257D%252C%2522params%2522%253A%257B%257D%257D reason: Unexpected token < in JSON at position 0

Not so sure, how to fix this one? Can we do any better error messaging on this one? I can help with the docs.

@frandiox
Copy link
Owner

Do you have a functions/props/home.[jt]s file? It either doesn't exists or is not returning valid JSON 🤔

@subhendukundu
Copy link
Author

I do have one like functions/props/home.js
Which has

export default {
  handler({ params = {}, query = {}, name = '' }) {
    return {
      data: {
        server: true,
        msg:
          'This is page ' +
          name.toUpperCase() +
          '. ' +
          process.env.VITEDGE_TEST,
      },
    }
  },
  options: {
    cache: {
      api: 90,
      html: 90,
    },
  },
}

Also is this a must for each page?

@frandiox
Copy link
Owner

That one looks fine but for some reason it fails to do JSON.stringify. Maybe the name is null or something like that so it throws?

Currently you need to disable props getter manually in the routes: { name, path, meta: { propsGetter: false } }. I thought about adding an option somewhere to change the propsGetter default 🤔

@subhendukundu
Copy link
Author

I have hardcoded the json. Still the same. :( Not really getting any hint, what is going wrong.
Would this help?

at /Users/mymac/Desktop/Projects/Higgle/cool.bio/cool-bio-analytics-worker-react/node_modules/node-fetch/lib/index.js:272:32
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Object.getRenderContext (file:///Users/mymac/Desktop/Projects/Higgle/cool.bio/cool-bio-analytics-worker-react/node_modules/vitedge/dev/middleware.js:224:28)
    at /Users/mymac/Desktop/Projects/Higgle/cool.bio/cool-bio-analytics-worker-react/node_modules/vite-ssr/dev/server.js:106:19 {
  type: 'invalid-json'

Add propsGetter: false in src/routes.js file?

@frandiox
Copy link
Owner

I cannot reproduce it, the code is the same as in the example in this repo but it doesn't happen there 🤔

I think the problem is here: https://github.com/frandiox/vitedge/blob/master/src/dev/middleware.js#L89
Some how it's not getting a valid object from the home.js handler. One thing you could do is basically modifying this file in your node_modules and add some console logs.

Add propsGetter: false in src/routes.js file?

Yes, there's more info here: https://vitedge.netlify.app/props.html#props-getter-locations (Disabling page props request for a route). Just pass false as the value and it should not make a props requests.

@subhendukundu
Copy link
Author

Okay, figured. I had two servers running on 3000 🙈
Stopped the other one, working as it should. Sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants