.toFixed - Vercel Deployment Prerender error
Answered
West African Lion posted this in #help-forum
West African LionOP
Hi! for some reason if I use .toFixed to ensure my coordinates (in lng,lat) are just 4 decimal places, it runs into a pre-render error in vercel during deployment. I already tried ensuring that the variables these are being applied to have a try-catch system to avoid being undefined but it still doesn't work. Any directions / help will be appreciated!
Error message:
Error message:
Error occurred prerendering page "/components/Modal". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of undefined (reading 'toFixed')
at i (/vercel/path0/v-mongo/.next/server/chunks/306.js:1:3133)
at Wc (/vercel/path0/v-mongo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
at Zc (/vercel/path0/v-mongo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
at Z (/vercel/path0/v-mongo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
at Zc (/vercel/path0/v-mongo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
at Z (/vercel/path0/v-mongo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
at Zc (/vercel/path0/v-mongo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
at Z (/vercel/path0/v-mongo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
at $c (/vercel/path0/v-mongo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
at bd (/vercel/path0/v-mongo/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
Generating static pages (6/13)
Generating static pages (9/13)
✓ Generating static pages (13/13)
> Export encountered errors on following paths:
/components/Modal
Error: Command "npm run build" exited with 115 Replies
West African LionOP
hi ! thanks for responding ! May I ask what fix I can do to still be able to round the coordinates to 4 places without the pre-render error? I tried wrapping it with a try catch but to no avail D:. I also tried having a default state in my useState and still doesn't work
@West African Lion hi ! thanks for responding ! May I ask what fix I can do to still be able to round the coordinates to 4 places without the pre-render error? I tried wrapping it with a try catch but to no avail D:. I also tried having a default state in my useState and still doesn't work
are you getting those coordinates from rsc?
West African LionOP
its from a database (mongoDB)
yeah and is that call in a rsc
server component
West African LionOP
sorry for this, but may I ask how I'll know if its in a RSC?
everything without "use client" at the top and returning tsx
West African LionOP
yea its in rsc. thanks for explaining!
u can opt out of prerendering using this https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic
export const dynamic = 'force-dynamic'Answer
add this to your page.tsx where u are fetching your db
and try again
West African LionOP
okay! ill try that for now and put back the .toFixed! thanks a lot!