0

When I run my angular5 app it builds fine. But when I run node dist/server.js I am getting the following error.

angular\node_modules\codemirror\lib\codemirror.js:18
var userAgent = navigator.userAgent;
            ^

ReferenceError: navigator is not defined
    at C:\Users\Lenovoz510\angular\kp\kpro-angular\node_modules\codemirror\lib\codemirror.js:18:17
    at userAgent (C:\Users\Lenovoz510\angular\kp\kpro-angular\node_modules\codemirror\lib\codemirror.js:11:82)
    at Object.<anonymous> (C:\Users\Lenovoz510\angular\kp\kpro-angular\node_modules\codemirror\lib\codemirror.js:14:2)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)

Can someone help me with a solution?

Abhinav Kinagi
  • 3,653
  • 2
  • 27
  • 43
  • 3
    Welcome to stackoverflow. Please include your code or a minimalistic and reprodocable example of your code. Otherwise you will have a tough time finding answers here. For reference check this site's [how to ask](https://stackoverflow.com/help/how-to-ask) – 5th Jun 25 '18 at 07:46
  • Ok.Please help me with a solution. – Nithya Sundar Jul 09 '18 at 08:42
  • Read the reference manuals and edit your question accordingly and you might get lucky! But tbh since you didn't adjust your question in the first hours, you likely will have to wait even longer to receive answers even if you edit it. – 5th Jul 09 '18 at 13:51
  • Thanks for your response. I am facing a similar issue and I have posted it here: https://stackoverflow.com/q/69430941/7584240 If you get a chance can you please have a look and provide some resolution. – BATMAN_2008 Oct 04 '21 at 05:54

1 Answers1

0

I understand from your question that you have installed CodeMirror. It is a JavaScript Library, which is designed for use in the browser and doesn't work in Node.js.

Fortunately, there is a Node.js compatible format of it, codemirror-node. See here,

Installation:

npm i codemirror-node

Usage:

var codemirror = require('codemirror');
var code = 'alert(1);';
var lang = 'javascript';

codemirror(code, lang);
Abhinav Kinagi
  • 3,653
  • 2
  • 27
  • 43
  • Thanks for your response. I am facing a similar issue and I have posted it here: https://stackoverflow.com/q/69430941/7584240 If you get a chance can you please have a look and provide some resolution. – BATMAN_2008 Oct 04 '21 at 05:53