mperdeck/jsnlog.js

XMLHttpRequest is not defined

Opened this issue · 2 comments

Yesterday I build an already running application and this error occurs on app.js on line
var JL = require('jsnlog').JL

Running the application with nodemon, it returns this error:


/home/osboxes/TCF/tcfWebServer/node_modules/jsnlog/jsnlog.js:91
    JL._createXMLHttpRequest = function () { return new XMLHttpRequest(); };
                                                        ^

ReferenceError: XMLHttpRequest is not defined
    at Function.JL._createXMLHttpRequest (/home/osboxes/TCF/tcfWebServer/node_modules/jsnlog/jsnlog.js:91:57)
    at new AjaxAppender (/home/osboxes/TCF/tcfWebServer/node_modules/jsnlog/jsnlog.js:601:28)
    at JL (/home/osboxes/TCF/tcfWebServer/node_modules/jsnlog/jsnlog.js:896:27)
    at Object.<anonymous> (/home/osboxes/TCF/tcfWebServer/node_modules/jsnlog/jsnlog.js:912:3)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/osboxes/TCF/tcfWebServer/app.js:21:27)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

Anybody can help me, please?
Thanks in advance

Alby

This is a bug in the last release. Essentially, this code assumes it is running on a browser. I assume you are running JSNLog on the server as a NodeJs program.

If you run jsnlog.js only on the server, you can safely remove that line
JL._createXMLHttpRequest = function () { return new XMLHttpRequest(); };
because JL._createXMLHttpRequest is only used in the AjaxAppender, which is only used on the browser.

I'll come up with a permanent fix as soon as I can.

I fixed this in version 2.25.1.