Closed matheeshaYapa closed 1 year ago
The error occurs on production mode, when running
next build
in my NextJS project.Following are the dependency list of the package.json
"dependencies": { "@nextui-org/react": "^1.0.0-beta.12", "@types/node": "20.1.7", "@types/react": "18.2.6", "@types/react-dom": "18.2.4", "eslint": "8.40.0", "eslint-config-next": "13.4.2", "googleapis": "^118.0.0", "next": "13.4.2", "react": "18.2.0", "react-dom": "18.2.0", "react-iconly": "^2.2.10", "react-toastify": "^9.1.3", "typescript": "5.0.4" }
This issue occurs due to the node version. My current version was 18.x and after I downgraded to 16.x, production build ran without any issue.
Any update on the fix? I do not think it has to do with the Node version.
Because "react-toastify": "^9.0.8"
working fine no node v18.12.1
but when i upgrade to "react-toastify": "^9.1.3"
then it breaks
@fkhadra can you check this because it's a big issue we cannot update the package at all
Ignore fixed it accordingly https://github.com/fkhadra/react-toastify/issues/889#issuecomment-1399455348
const ToastContainer = dynamic(() => import('react-toastify').then((module) => module.ToastContainer), { ssr: false, // Disable server-side rendering });
export const LazyToastContainer = () => ( <ToastContainer position="bottom-right" autoClose={5000} hideProgressBar={false} newestOnTop={false} rtl={false} pauseOnFocusLoss draggable pauseOnHover toastStyle={{ background: 'none' }} closeButton={false} /> );
load LazyToastContainer in your main component and see the magic
A solution with example. The idea to use isMount for lazy components is used in NextJS documentation in some places, so it is officialy acceptable.
function Layout({ yourParams }: LayoutProps) {
const [isMount, setMount] = useState(false)
useEffect(() => {
setMount(true)
}, [])
return (
<div>
<Head>
<title>"Your title</title>
<meta name="description" content="Your content" />
<link rel="icon" href="/logo.svg" />
</Head>
{isMount && (
<ToastContainer
style={{ width: '101%', height: '36px' }}
position="bottom-center"
toastClassName={({ type }) => contextClass[type || 'default']}
hideProgressBar={true}
icon={false}
closeButton={false}
newestOnTop={true}
transition={Slide}
bodyClassName={() => 'p-4 text-sm font-white font-med block'}
autoClose={2000}
/>
)}
<div className="flex flex-col items-center ">
<main className="flex justify-center items-center w-full">{children}</main>
</div>
</div>
)
}
Also, I noticed you didn't post any part of your code. A common cause of this issue is when you are using a hook outside of a component.
The error occurs on production mode, when running
next build
in my NextJS project.Following are the dependency list of the package.json
"dependencies": { "@nextui-org/react": "^1.0.0-beta.12", "@types/node": "20.1.7", "@types/react": "18.2.6", "@types/react-dom": "18.2.4", "eslint": "8.40.0", "eslint-config-next": "13.4.2", "googleapis": "^118.0.0", "next": "13.4.2", "react": "18.2.0", "react-dom": "18.2.0", "react-iconly": "^2.2.10", "react-toastify": "^9.1.3", "typescript": "5.0.4" }