question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReferenceError: navigator is not defined

See original GitHub issue

ReferenceError: navigator is not defined W20161022-17:29:38.375(-4)? (STDERR) at /Users/mattmacpherson/Code/project/node_modules/codemirror/lib/codemirror.js:24:19 W20161022-17:29:38.375(-4)? (STDERR) at userAgent (/Users/mattmacpherson/Code/project/node_modules/codemirror/lib/codemirror.js:12:22) W20161022-17:29:38.376(-4)? (STDERR) at Object.<anonymous> (/Users/mattmacpherson/Code/project/node_modules/codemirror/lib/codemirror.js:17:3) W20161022-17:29:38.376(-4)? (STDERR) at Module._compile (module.js:409:26) W20161022-17:29:38.376(-4)? (STDERR) at Object.Module._extensions..js (module.js:416:10) W20161022-17:29:38.376(-4)? (STDERR) at Module.load (module.js:343:32) W20161022-17:29:38.377(-4)? (STDERR) at Module.Mp.load (/Users/mattmacpherson/.meteor/packages/babel-compiler/.6.9.1_1.15j1r1l++os+web.browser+web.cordova/npm/node_modules/reify/node/runtime.js:16:23) W20161022-17:29:38.377(-4)? (STDERR) at Function.Module._load (module.js:300:12) W20161022-17:29:38.378(-4)? (STDERR) at Module.require (module.js:353:17) W20161022-17:29:38.378(-4)? (STDERR) at require (internal/module.js:12:17)

I only get this error when requiring modes:

require('codemirror/mode/javascript/javascript'); require('codemirror/mode/xml/xml'); require('codemirror/mode/markdown/markdown');

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:11
  • Comments:14

github_iconTop GitHub Comments

64reactions
Salakarcommented, Feb 13, 2017

@Method-X @sslotsky had the same issue here using next.js and SSR - I’ve worked around this issue by importing as follows:

let CodeMirror = null;
if (typeof window !== 'undefined' && typeof window.navigator !== 'undefined') {
  CodeMirror = require('react-codemirror');
  require('codemirror/mode/yaml/yaml');
  require('codemirror/mode/dockerfile/dockerfile');
}

And then rendering:

// render
   { CodeMirror && <CodeMirror ... /> }

After which it’s only the client now that renders, on the server it’s ignored. Does the job 👍

9reactions
songyulecommented, Mar 19, 2020

if you are using NextJS, maybe you can use this easier way

import dynamic from 'next/dynamic'; const CodeMirror = dynamic(() => import('react-codemirror'), { ssr: false });

Read more comments on GitHub >

github_iconTop 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 >
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
Read more >
Uncaught ReferenceError: navigator is not defined - Workers
If your libraries/dependencies rely on more of navigator than that, it'll be time for polyfills (or investigating if that dependency will work ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found