-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReferenceError: navigator is not defined #77
Comments
Are you using server side rendered react? There won't be a navigator until the doc is ready. |
This was supposedly fixed but still happens as noted in #21 I would also like to use this package with SSR and currently cannot for this reason. |
Seems it was removed here: |
@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 👍 |
@Salakar Thanks that worked fantastically! For what it's worth, |
I have a similar error, when i try to use react-player dependency, someone could helpme |
It seems the trick from above no longer works in NextJs. This is a terrible hack but the following works for now (if there is a better way in nextjs to do this please share). In the imports/requires
and in the render method
|
thank you :) |
if you are using NextJS, maybe you can use this easier way
|
@songyule Can you please help me with the full code where it is used please ? |
Something like this should work, @prashantchothani
|
Thanks @sombreroEnPuntas It worked |
react-codemirror2 this method working. import { Controlled as CodeMirror } from "react-codemirror2"; let modeLoaded = false return ( |
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');
The text was updated successfully, but these errors were encountered: