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

undefined cannot be serialized as JSON. #4

Open
s3689 opened this issue Jul 5, 2022 · 4 comments
Open

undefined cannot be serialized as JSON. #4

s3689 opened this issue Jul 5, 2022 · 4 comments

Comments

@s3689
Copy link

s3689 commented Jul 5, 2022

my website:
http://207.246.109.130:3000
ubuntu 22.04
next@10.2.3
algoliasearch@4.13.1

http://207.246.109.130:3000/search?q=test
(Algolia is configured, and the data can also be seen in the background)

http://207.246.109.130:3000/user?idaaa=test

Server Error:
Error: Error serializing .totalNumOfHits returned from getServerSideProps in "/search".
Reason: undefined cannot be serialized as JSON. Please use null or omit this value.

Call Stack
isSerializable
file:///root/HeckarNews/website/node_modules/next/dist/lib/is-serializable-props.js (7:95)

file:///root/HeckarNews/website/node_modules/next/dist/lib/is-serializable-props.js (7:490)
Array.every

isSerializable
file:///root/HeckarNews/website/node_modules/next/dist/lib/is-serializable-props.js (7:291)
isSerializableProps
file:///root/HeckarNews/website/node_modules/next/dist/lib/is-serializable-props.js (9:219)
renderToHTML
file:///root/HeckarNews/website/node_modules/next/dist/next-server/server/render.js (42:1318)
processTicksAndRejections
node:internal/process/task_queues (96:5)
async
file:///root/HeckarNews/website/node_modules/next/dist/next-server/server/next-server.js (112:97)
async
file:///root/HeckarNews/website/node_modules/next/dist/next-server/server/next-server.js (105:142)
async DevServer.renderToHTMLWithComponents
file:///root/HeckarNews/website/node_modules/next/dist/next-server/server/next-server.js (137:387)
async DevServer.renderToHTML
file:///root/HeckarNews/website/node_modules/next/dist/next-server/server/next-server.js (138:610)
async DevServer.renderToHTML
file:///root/HeckarNews/website/node_modules/next/dist/server/next-dev-server.js (36:578)
async DevServer.render
file:///root/HeckarNews/website/node_modules/next/dist/next-server/server/next-server.js (75:160)
async Object.fn
file:///root/HeckarNews/website/node_modules/next/dist/next-server/server/next-server.js (58:672)
async Router.execute
file:///root/HeckarNews/website/node_modules/next/dist/next-server/server/router.js (25:67)
async DevServer.run
file:///root/HeckarNews/website/node_modules/next/dist/next-server/server/next-server.js (68:1042)

your website will be fine:
https://forum.krehwell.com/search?q=test
https://forum.krehwell.com/user?idaaa=yakuza

How to solve it?
Also, how can I prevent error messages from appearing on the browser side?

@krehwell
Copy link
Owner

krehwell commented Jul 5, 2022

I'm not sure about what causes the error,

Also, how can I prevent error messages from appearing on the browser side?

basically you can get rid of error on by not passing an undefined value from getServerSideProps return value,
so in this case since the causes of undefined value is totalNumOfHits, you can change it to:

export async function getServerSideProps({ query }) {
    const apiResult = await getAlgoliaData(query);

    return {
        props: {
            totalNumOfHits: apiResult?.nbHits || null,
           // ...rest
        },
    };
}

@s3689
Copy link
Author

s3689 commented Jul 5, 2022

I'm not sure about what causes the error,

Thank you, I have tried all the methods on the Internet, but it still doesn't work. Hopefully the Docker version can be added.

@krehwell
Copy link
Owner

krehwell commented Jul 5, 2022

aa sorry for that. not sure if i'm gonna improve this project any further though. you could replace the search using another service anyway, but I suggest to just tweaking the algolia on your repo to make it work on your case instead since implementation can be anything but the flow has already been there

@s3689
Copy link
Author

s3689 commented Jul 6, 2022

aa sorry for that. not sure if i'm gonna improve this project any further though. you could replace the search using another service anyway, but I suggest to just tweaking the algolia on your repo to make it work on your case instead since implementation can be anything but the flow has already been there

Don't be sorry, that's ok, but thank you anyway for your project and help, hope you can continue, your project is great! I will support you!

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