Open crebro opened 2 years ago
you are probably using it in the framework where the window or document do not exist initially, like Next.js.
I am curios what would be the reasonable way of making it work there, as I also struggled with it now :/ @samdenty maybe you have an idea knowing the library internals
I'm also encountering this error and using Next.js (as @d-ivashchuk suspected).
My workaround is to declare the functions outside the component and then dynamically import the package in a useEffect
, something like this
let Hook
let Unhook
// some code ...
useEffect(() => {
(async () => {
({ Console, Hook, Unhook } = await import("console-feed"));
Hook(iframeRef.current.contentWindow.console, (log) => ((state) => [...state, log]), false);
})();
const dynRef = iframeRef.current;
return () => Unhook(iframeRef.current.contentWindow.console)
}, []);
Doesn't fix the underlying problem but works fine until the issue is fixed
I am currently working on an application that needs to get the console feed of an iframe although I don't think the application has anything to do with the error because it shows up just when I import anything without using it at all.
The following is the code that I am using in my application.