Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Failed to Server Render (SSR) #31

Open
driuqzy opened this issue Sep 3, 2023 · 3 comments
Open

Failed to Server Render (SSR) #31

driuqzy opened this issue Sep 3, 2023 · 3 comments

Comments

@driuqzy
Copy link

driuqzy commented Sep 3, 2023

Pixi.js works great in SSR environments like Gatsby.

But as soon as I add import { SpriteH } from 'pixi-heaven to my project SSR breaks with the following error, and I can't seem to get around it even though the line of code I have that uses SpriteH is not called on the server side. I assume the library initializes immediately prior to my code execution.

I'd like to use pixi-heaven for the performance benefits of alpha sprite masking.

Failed to Server Render (SSR)
Error message:
ReferenceError: document is not defined

File:
node_modules/@pixi/settings/lib/adapter.mjs:3:1

Stack:
WebpackError: ReferenceError: document is not defined
    at artshop-ai/node_modules/@pixi/settings/lib/adapter.mjs:3:1
    at artshop-ai/node_modules/@pixi/core/lib/textures/Texture.mjs:278:22
    at artshop-ai/node_modules/pixi-heaven/lib/twotint/sprites/MaskedBatchRenderer.mjs:5:15
    at artshop-ai/webpack/bootstrap:19:1
    at artshop-ai/webpack/bootstrap:19:1
    at artshop-ai/webpack/bootstrap:19:1
    at artshop-ai/webpack/bootstrap:19:1
    

I also tried dynamic imports but then I get a different problem that likely requires some re-initialization of the pixi library possibly?:

Error in function BatchSystem.setObjectRenderer in ./node_modules/@pixi/core/lib/batch/BatchSystem.mjs:16
Cannot read properties of undefined (reading 'start')

./node_modules/@pixi/core/lib/batch/BatchSystem.mjs:16
@ivanpopelyshev
Copy link
Collaborator

it should be easy to fix and rebuild . I dont think anyone will do that right now except you )

@driuqzy
Copy link
Author

driuqzy commented Sep 3, 2023

Can you point me in direction for fix?

@driuqzy
Copy link
Author

driuqzy commented Sep 4, 2023

For now, I was able to solve the SSR issue by editing the node_modules/@pixi files that presented SSR errors, and wrapping various things with:

if (typeof window !== "undefined") {

}

and persisting my changes in deployments by using https://www.npmjs.com/package/patch-package

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

No branches or pull requests

2 participants