Skip to content

Integrate excalibur with next.js #1886

Answered by kamranayub
EduardoHidalgo asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @EduardoHidalgo (and anyone else), here's an example of using Excalibur with Next. Since Excalibur can only execute on the client, it needs to be loaded via useEffect and a dynamic import otherwise Next will attempt to run the module in SSR. Unfortunately, right now we don't check for window existence so it bombs in SSR.

https://codesandbox.io/s/next-excalibur-5b18x?file=/game/game.js

FYI, this is still an issue in 0.24.5 which is exacerbated by HMR: #1431

Could workaround by clearing the element by tag name/query selector when effect runs.

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@kamranayub
Comment options

Comment options

You must be logged in to vote
1 reply
@kamranayub
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by kamranayub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants