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: Worker is not defined #15

Closed
notchris opened this issue Feb 8, 2024 · 14 comments · Fixed by pixijs/pixijs#10227
Closed

ReferenceError: Worker is not defined #15

notchris opened this issue Feb 8, 2024 · 14 comments · Fixed by pixijs/pixijs#10227

Comments

@notchris
Copy link

notchris commented Feb 8, 2024

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
Copy link

I'm also having this issue.

@oldben87
Copy link

oldben87 commented Feb 17, 2024

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
Copy link
Author

notchris commented Feb 26, 2024

@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
Copy link
Member

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

@notchris
Copy link
Author

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

@notchris
Copy link
Author

notchris commented Mar 4, 2024

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

@shanealsingh
Copy link

@notchris bump 👍

@notchris
Copy link
Author

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

@shanealsingh
Copy link

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

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

:(

@bigtimebuddy
Copy link
Member

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

@shanealsingh
Copy link

@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
Copy link
Member

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

@bigtimebuddy
Copy link
Member

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
Copy link

shanealsingh commented Mar 20, 2024

@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 :)

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

Successfully merging a pull request may close this issue.

5 participants