Sinchana hs
Sinchana hs

Reputation: 100

SyntaxError: Cannot use import statement outside a module in nextjs

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

Upvotes: 2

Views: 4490

Answers (1)

Paramesh Krishna
Paramesh Krishna

Reputation: 98

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 })

Upvotes: 4

Related Questions