Next.js Discord

Discord Forum

help with peerjs

Answered
gin posted this in #help-forum
Open in Discord
ginOP
Im trying to import peerjs into my clientside component, now the issue is that it is telling me that navigator is not defined. I already found the fix but that requires modifying the library itself to check for the navigator api to be avaible before init. Any other tricks i can do to fix that issue?
Answered by gin
created a npm package with the fix
View full answer

5 Replies

ginOP
Error:
⨯ node_modules\peerjs\dist\bundler.mjs (108:19) @ navigator
 ⨯ ReferenceError: navigator is not defined


fix from github -> check for navigator int this call ->
readonly isIOS = typeof navigator !== "undefined" && ["iPad", "iPhone", "iPod"].includes(navigator.platform);


isIOS is required when the package is imported
soooo, can i fix this issue using nextjs iself? as i said this is checked after import so checking for navigator myself wont fix the issue
maybe i can dynamically import the library after the check?
can i import modules with next/dynamic?
ginOP
created a npm package with the fix
Answer