Skip to content
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

node.js > ReferenceError: eoParse is not defined #4

Open
ubarbaxor opened this issue Feb 23, 2018 · 1 comment
Open

node.js > ReferenceError: eoParse is not defined #4

ubarbaxor opened this issue Feb 23, 2018 · 1 comment

Comments

@ubarbaxor
Copy link
Contributor

ReferenceError: window is not defined in Node.js

/Users/ubarbaxor/code/imagery-watcher/node_modules/libcoverage/src/parse.js:12
if (typeof window.DOMParser != "undefined") {
^

ReferenceError: window is not defined
    at Object.<anonymous> (/Users/ubarbaxor/code/imagery-watcher/node_modules/libcoverage/src/parse.js:12:1)
    at Module._compile (module.js:624:30)
    at Object.Module._extensions..js (module.js:635:10)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Module.require (module.js:568:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/ubarbaxor/code/imagery-watcher/src/index.js:98:21)
    at Module._compile (module.js:624:30)

I've been checking in src/parse.js:12 there's something in the taste of :

if (typeof window.DOMParser != "undefined") { ... }
else if (typeof window.ActiveXObject != "undefined" &&
        new window.ActiveXObject("Microsoft.XMLDOM")) { ... }

This causes ReferenceError: window is not defined in node.js.

A simple solution would be to wrap the whole block in something in the taste of :

if (typeof window != "undefined") { ... }

I'm not sure this lib is meant to be usable in node, currently trying it to integrate DigitalGlobe API, so I had to fork and fix this myself.

I'm willing to issue a PR in case this issue can be addressed.

@constantinius
Copy link
Contributor

Hi @ubarbaxor

Thanks for raising this issue and providing an PR! In fact, libcoverage.js was initially conceived before node.js was actually at the point of popularity it is today, so it was considered "browser-only". Much has changed since that, and I'm very much in favor of supporting node.js as-well.

Unfortunately, as demonstrated by the issue you raised, XML handling is rather different in the browser than with node and more work is required to be really on par with the browsers capabilities (I'm talking about DOM parsing and xPath expressions especially).

This can be done step by step, so making the request part of libcoverage.js work under node is already a great improvement!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants