Next.js Discord

Discord Forum

.toFixed - Vercel Deployment Prerender error

Answered
West African Lion posted this in #help-forum
Open in Discord
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 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 1
Answered by gin
export const dynamic = 'force-dynamic'
View full answer

15 Replies

@West African Lion 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 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 1
this happens cause on prerendering nextjs tries to execute any ssr code that can be cached
and in this case your number or whatever u apply .ToFixed is undefined
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 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!
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!