pixijs / node

Run PixiJS but in Node.js environments, no browser required!
https://pixijs.com
MIT License
30 stars 4 forks source link

ReferenceError: Worker is not defined #15

Closed notchris closed 5 months ago

notchris commented 5 months ago

System: Macbook, Apple M2 Pro, MacOS Ventura

Issue: When creating a new Application class, I get the following error:

ReferenceError: Worker is not defined
/node_modules/@pixi/assets/lib/_virtual/checkImageBitmap.worker.js:22

"@pixi/node": "^7.3.0",

vincaslt commented 5 months ago

I'm also having this issue.

oldben87 commented 5 months ago

I am seeing this too

Reproduction code:

import { Application, Graphics } from "@pixi/node"
import { writeFileSync } from "fs"

const app = new Application()

const square = new Graphics()

app.stage.addChild(square)

app.renderer.render(app.stage)
const base64Image = app.renderer.extract
  .canvas(app.stage)
  .toDataURL("image/png")

const base64Data = base64Image.replace(/^data:image\/png;base64,/, "")
const output = `./test.png`

writeFileSync(output, base64Data, "base64")
notchris commented 4 months ago

@bigtimebuddy Will this be available when pixi does another release? I tried to update the webworker-plugin directly, but was unable to get around the Worker issue.

bigtimebuddy commented 4 months ago

Yeah, I'm trying to get 7.4.1 out this week. Hang tight should be resolved soon.

notchris commented 4 months ago

@bigtimebuddy Ah, you're awesome - thank you again!

notchris commented 4 months ago

@bigtimebuddy Wanted to check in on the status, I saw https://github.com/pixijs/pixijs/pull/10254 is awaiting a review. Are we still waiting on a PIXI release?

shanealsingh commented 4 months ago

@notchris bump 👍

notchris commented 4 months ago

@shanealsingh TY for the bump, I think this got resolved in the newest release, right @bigtimebuddy ?

shanealsingh commented 4 months ago

@notchris Did you try? Just tried it out n got:

class WorkerInstance extends Worker {
                             ^
ReferenceError: Worker is not defined

:(

bigtimebuddy commented 4 months ago

I just published pixi.js@7.4.2. Can you try that version which has the fix for this Worker issue

shanealsingh commented 4 months ago

@bigtimebuddy I wonder if i'm doing something wrong.

yarn add @pixi/node

I have a simple test file:

import { Application } from '@pixi/node';

import express from 'express';

const app = express();
const port = 3000;

app.get('/', async (req, res) => {
    // Create a new application
   const app = new Application();

    res.send('Hello World!');
});

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`);
});

Still seeing the same issue :(

bigtimebuddy commented 4 months ago

Yeah, this is a publishing problem with dist-tags. Working on fixing now.

bigtimebuddy commented 4 months ago

I verified that this is fixed. Here's the hello-world setup:

{
  "name": "pixi-node-test",
  "version": "1.0.0",
  "description": "",
  "type": "module",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@pixi/node": "^7.3.0"
  }
}
import { Application, Assets, Sprite } from '@pixi/node';
import path from 'path';
import { writeFileSync } from 'fs';

// This package requires the new asset loader to be used.
// Initialize the new assets loader
await Assets.init();

// The application will create a renderer using WebGL. It will also setup the ticker
// and the root stage Container.
const app = new Application();

// load a sprite
const bunnyTexture = await Assets.load(path.join(process.cwd(), 'bunny.png'));
// create sprite from texture
const bunny = Sprite.from(bunnyTexture);

// Setup the position of the bunny
bunny.x = app.renderer.width / 2;
bunny.y = app.renderer.height / 2;

// Rotate around the center
bunny.anchor.x = 0.5;
bunny.anchor.y = 0.5;

// Add the bunny to the scene we are building.
app.stage.addChild(bunny);

// Listen for frame updates
app.ticker.add(() => {
    // each frame we spin the bunny around a bit
    bunny.rotation += 0.01;
});

// extract and save the stage
app.renderer.render(app.stage);

const base64Image = app.renderer.view.toDataURL('image/png');
const base64Data = base64Image.replace(/^data:image\/png;base64,/, '');
const output = `./test.png`;

writeFileSync(output, base64Data, 'base64');

process.exit(0);
shanealsingh commented 4 months ago

@bigtimebuddy I did a quick test in my repo. Looks good. I don't see the Worker error. Thank you for the quick response and fix :)