SyntaxError: Cannot use import statement outside a module in nextjs

Viewed 967

I'm using "react-d3-speedometer" library but getting the above error while importing. can anyone help with this?

1 Answers

This is because NextJS tries to do the server-side rendering and they are components that depend on the browser.

you can fix this by using dynamic import disabling server-side rendering:

import dynamic from 'next/dynamic'
const ReactSpeedometer = dynamic(import ("react-d3-speedometer"), { ssr: false })
Related