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

Running in Node.js: HTMLElement is not defined #468

Closed
koko236 opened this issue Aug 16, 2017 · 3 comments
Closed

Running in Node.js: HTMLElement is not defined #468

koko236 opened this issue Aug 16, 2017 · 3 comments
Labels

Comments

@koko236
Copy link

koko236 commented Aug 16, 2017

Hi,

I try to run matter-js serverside in node. Actually I have browser simulation which I'm porting to the server now. I got rid of renderer and now the obstacle is when I run most basic code:

var Mt = require('matter-js')
this.engine = Mt.Engine.create() // throws error: 'HTMLElement is not defined'

Which points me right to the very beginning of the Engine.create() function:

Engine.create = function(element, options) {
        // options may be passed as the first (and only) argument
        options = Common.isElement(element) ? options : element; /// <----
        element = Common.isElement(element) ? element : null;
        options = options || {};
(...)

and:

Common.isElement = function(obj) {
        return obj instanceof HTMLElement;
    };

This is SO obvious that I suspect I may be doing something totally wrong. I can't see any mention of Node specific setup in the getting started...

@koko236
Copy link
Author

koko236 commented Aug 16, 2017

I temp fixed it by patching Common.isElement():

Common.isElement = function(obj) {
        return typeof HTMLElement !== 'undefined' && obj instanceof HTMLElement;
    };

but now I see unchecked references to window in Common.now(). I can fix this as well but I don't know how far down the rabbit hole this will lead me so here's my more general question:

Is the master branch of matter-js supposed to work in nodejs environment at all?

@koko236
Copy link
Author

koko236 commented Aug 17, 2017

FYI, safeguarding references to window in Common.now seems to fix the engine for Node at least for my current use case.

@liabru
Copy link
Owner

liabru commented Aug 17, 2017

Yeah it supports node but looks like I've slipped up here, thanks for the heads up. I'll handle fixing all the reference issues. Also related is #459.

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

No branches or pull requests

2 participants