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

poly-decomp currently not working with browserify #365

Closed
KernelDeimos opened this issue Feb 6, 2017 · 2 comments
Closed

poly-decomp currently not working with browserify #365

KernelDeimos opened this issue Feb 6, 2017 · 2 comments

Comments

@KernelDeimos
Copy link

Let me know if I'm wrong on this, but I think poly-decomp isn't working.

I installed the module using npm install --save poly-decomp.

After that didn't work, I tried to globalise a decomp variable by doing this:

if (typeof window === 'undefined') {
    global.window = {}
}
window.decomp = require 'poly-decomp'

Since I want to use the same code base for my client and server, I needed to create a window object to use when it doesn't exist. Since I'm checking if window exists already, I think this should work.

The error I receive is: decomp.Polygon is not a constructor

@KernelDeimos
Copy link
Author

I managed to remove the first issue by installing matter-js directly from GitHub

npm remove --save matter-js
npm install --save liabru/matter-js

but now matter-js complains that poly-decomp doesn't exist. (this is what happened earlier before I added it to the window object, however the updated version of matter-js no longer checks window)

I'm not entirely sure how this works though - I see require('poly-decomp') at the beginning of Bodies.js, so I would figure either it would work or the require would have thrown the error instead.

I tried modifying Bodies.js to take decomp as a parameter, but that didn't work either for some reason.

@liabru
Copy link
Owner

liabru commented Feb 6, 2017

I'm using browserify-shim to make the require work. It seems to output this line:

var decomp = (typeof window !== "undefined" ? window['decomp'] : typeof global !== "undefined" ? global['decomp'] : null);

Looking at it, I'm not sure how it's actually meant to work in an environment where require is available... doh. I was expecting it to have a check for require before looking for globals. I'll need to look into it, but maybe you could try this for now at your code entry point:

global.decomp = require('poly-decomp');

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

No branches or pull requests

2 participants