desandro / draggabilly

:point_down: Make that shiz draggable
https://draggabilly.desandro.com
MIT License
3.86k stars 387 forks source link

Fix for React/Node #167

Closed jrock17 closed 2 years ago

jrock17 commented 7 years ago

Is there a way to use this (and packery) in a React/NodeJS environment?

When I try to require, I get a bunch of errors around 'window is not defined'.

Thanks!

desandro commented 7 years ago

Hello! Thanks for reporting this issue.

Draggabilly was designed for the browser. See https://github.com/desandro/draggabilly/pull/101#issuecomment-140589998

I feel like the conditional should be higher up — this module shouldn't be loaded in the first place

That said, I'm open to improving support for server-side rendering, so these errors don't get in the way of your development. Could you help me understand what you're looking for?

jrock17 commented 7 years ago

I'm not sure what the fix is. But the error I get is: packery.js:481 })( window ); ^ ReferenceError: window is not defined

I've tried some node/react ports but they don't seem to work. Would be great if it was compatible.

yaodingyd commented 7 years ago

@jrock17 you can add the following in your entry point:

if (typeof window === 'undefined') {
    global.window = global
}

This is more of a hack and it should work for your situation.

desandro commented 2 years ago

Draggabilly v3 has been released that checks for window and falls back to this.