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

ReferenceError: document is not defined #2

Open
human211 opened this issue Apr 15, 2023 · 3 comments
Open

ReferenceError: document is not defined #2

human211 opened this issue Apr 15, 2023 · 3 comments

Comments

@human211
Copy link

human211 commented Apr 15, 2023

Hi!

only one string
const app = new Application();
and i have error
ReferenceError: document is not defined at new AccessibilityManager (D:\test\node_modules@pixi\accessibility\src\AccessibilityManager.ts:96:21)

an error appears if the monorepe uses
pixi 7.2.4 for frontend and @pixi/node for backend

dep: "@pixi/node": "7.2.0"

start: node dist/main.js

I tried to run a test project with an example from the pixijs/node readme.md file
however, it also didn't work with an error

PS D:\test2> node index.js
file:///D:/test2/node_modules/@pixi/extract/lib/Extract.mjs:51
const imageData = new ImageData(new Uint8ClampedArray(pixels.buffer), width, height);
^

ReferenceError: ImageData is not defined
at _Extract.canvas (file:///D:/test2/node_modules/@pixi/extract/lib/Extract.mjs:51:23)
at file:///D:/test2/index.js:38:6
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

@galipmedia
Copy link

Same issue.

Seems the code doesn't actually work which is sad :(

@fenetic
Copy link

fenetic commented May 24, 2023

Hey, this is a node-canvas issue, solution here: Automattic/node-canvas#2003 (comment)

@rob-myers
Copy link

Although the above solutions didn't work for me, the following did:

import { Canvas, ImageData } from 'canvas';
import { Application } from "@pixi/node";

const app = new Application();
// ...

const pixels = new Uint8ClampedArray(app.renderer.extract.pixels(app.stage));
const imageData = new ImageData(pixels, chosenWidth, chosenHeight);

const canvas = new Canvas(chosenWidth, chosenHeight);
const ctxt = canvas.getContext('2d');
ctxt.putImageData(imageData, 0, 0);

await stream.pipeline(
    canvas.createPNGStream(), 
    fs.createWriteStream(outputPath),
)

app.destroy();

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

4 participants