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

Support Isomorphic Apps? #1092

Closed
L1lith opened this issue Apr 1, 2022 · 4 comments
Closed

Support Isomorphic Apps? #1092

L1lith opened this issue Apr 1, 2022 · 4 comments

Comments

@L1lith
Copy link
Contributor

L1lith commented Apr 1, 2022

When you import melonjs in Node it immediately throws an error because it can't access the window before you even call anything at all. I was thinking it would be cool if it wouldn't access the window unless the libraries actually started rendering because when I try to deploy my isomorphic app it can't run my app inside the Node.js server.

I understand this isn't a big issue for Melon.js overall but I do think it would be cool to have better integration with JS frameworks with Isomorphic rendering like Solid.js and React (with Next.js etc)

I also think this goes along with this issue, and is a good design pattern in my opinion because things probably shouldn't run in a global context, but rather when their respective functions are called. That's my 2 cents anyways, feel free to take this suggestion with a grain of salt.

I haven't deployed MelonJS to an isormophic application yet, but I was trying to do some testing of my app inside Node.js and importing MelonJS was causing the app to break during testing which was a little frustrating.

@obiot
Copy link
Member

obiot commented Apr 30, 2022

Hi,

as a first step, I will replace reference to window by globalThis, this will fix access to the global instance for browser, node, and also web workers :

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
https://caniuse.com/mdn-javascript_builtins_globalthis

@obiot
Copy link
Member

obiot commented May 1, 2022

Hi @L1lith any chance for your to test the last version ?

latest 10.7.0 version using globalThis instead of window has been updated here :
https://github.com/melonjs/melonJS/tree/master/dist

thanks!

@obiot
Copy link
Member

obiot commented May 2, 2022

Hi @L1lith , so many changes as you can see over the weekend, but now melonJS does not crash anymore when executed in node.js 🎉 🎉 🎉

I haven't tried it but even though it's being "loaded" it will still require at least jsdom and node-canvas to work properly.

In case you are testing this further, feel free to share any more return of experience with using those two together with melonJS

Thanks again !

@obiot
Copy link
Member

obiot commented May 4, 2022

Hi,

with the latest 10.7.0 release, that now allows to run melonJS in node.js without crashing, I will close this ticket.

For further information, and maybe more return of experience mixing melonJS & node.js, I invite you to continue the discussion on the topic I created in our new forum :
https://melonjs.discourse.group/t/running-melonjs-in-node-js/17

thanks again @L1lith for the feedback and suggestion !

@obiot obiot closed this as completed May 4, 2022
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