Open davinpalmtreenft opened 1 year ago
So I just created a clean react app with create-react-app and the error did not occur so it is definitely isolated to my app and most likely a result of how nextjs renders the page. I am going to try a clean nextjs app next to see if the error persists there as well.
Ok and on a clean create-next-app I was able to confirm that the error persists. Would you consider adding support for nextjs?
I have resolved the issue by dynamically loading the component that utilizes browser-solidity-compiler
import dynamic from 'next/dynamic';
const Compiler = dynamic(
import('@/web3/Compiler').then((lib) => lib.default),
{ ssr: false }
);
For reference: https://dev.to/vvo/how-to-solve-window-is-not-defined-errors-in-react-and-next-js-5f97 (nextjs solutions for window not defined reference error) https://nextjs.org/docs/advanced-features/dynamic-import#with-no-ssr (nextjs docs) https://github.com/vercel/next.js/issues/4515 (discussion as it relates to typescript)
That works, disabling SSR solves the issue.
I am running this package in a nextjs react app.
When I refresh the page that
solidityCompiler
is loaded on I receive the following error:I have tried wrapping the function that calls it with
if (typeof window !== "undefined)
as suggested here: https://dev.to/vvo/how-to-solve-window-is-not-defined-errors-in-react-and-next-js-5f97 however the error persisted.I also tried running my function inside of useEffect hook which is supposed to guarantee client side code running and then I receive this error:
Steps to reproduce would be to run solidityCompiler within a nextjs app. I know next does a lot with server side rendering etc so this may be the cause of the issue.