ReferenceError: navigator is not defined
See original GitHub issueWhat version of Next.js are you using?
11.0.1
What version of Node.js are you using?
14.17.1
What browser are you using?
chrome,mozilla
What operating system are you using?
windows
How are you deploying your application?
vercel
Describe the Bug
export default function Editor() {
> 4 | let abc= navigator;
| ^
5 | return (<>
6 | {JSON.stringify(abc)}
7 | </>)
Expected Behavior
Just run normally
To Reproduce
Create a file say editor.js
export default function Editor() {
let abc= navigator;
return (<>
{ JSON.stringify(abc) }
</>)
}
Just run and open this page in browser
same will happen for window
It will result to ReferenceError: navigator is not defined
If you direct access then also it will show error
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
node.js - ReferenceError: navigator is not defined
I assume that the problem is that Navigator.geolocation is a Web API and doesn't work on node. Is there a way to mock...
Read more >ReferenceError: navigator is not defined · Issue #522 · vercel/swr
Bug report Description / Observed Behavior When building the app with NextJS in Jenkins, the build fails with the following error message: ...
Read more >Navigator is not defined----bug - Theia Community
navigator is a browser API. If you require code in the backend that ends up executing browser scripts you will get errors.
Read more >navigator is not defined node js - You.com | The AI Search ...
[Solved]-ReferenceError navigator is not defined for FingerprintJS-node.js ... Accepted answer. I have found that fingerprintjs2 is a Javascript Library, doesn't ...
Read more >Getting "ReferenceError: navigator is not defined" in Next.js app
Getting error - ReferenceError: navigator is not defined error from Plasmic in development and production for our NextJS app 3:18:27 PM: ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Try loading the library with dynamic imports on client side.
https://stackoverflow.com/questions/66291720/import-peerjs-to-nextjs
Hi,
you are accessing
window
andnavigator
on server. These variables are undefined there. I suggest reading official docs.Checking this article or this article or Googling.
The easiest solution will be wrapping
window
/navigator
inuseEffect()
to run it only on the client side and not on server.