node icon indicating copy to clipboard operation
node copied to clipboard

ReferenceError: document is not defined

Open human211 opened this issue 2 years ago • 3 comments

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)

human211 avatar Apr 15 '23 14:04 human211

Same issue.

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

galipmedia avatar May 23 '23 14:05 galipmedia

Hey, this is a node-canvas issue, solution here: https://github.com/Automattic/node-canvas/issues/2003#issuecomment-1356245951

fenetic avatar May 24 '23 10:05 fenetic

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();

rob-myers avatar Dec 11 '23 15:12 rob-myers