pixijs: Bug: 'Worker is not defined' with Pixi 7.4.0 and Node v18.17.1

Current Behavior

We have a test suite using Node Test Runner and running with Node v18.17.1 and after installing the latest v7.4.0 Pixi release our tests are throwing a new error:

file:///Users/bryan/Projects/rapid/node_modules/@pixi/assets/lib/_virtual/checkImageBitmap.worker.mjs:20
class WorkerInstance extends Worker {
                             ^

ReferenceError: Worker is not defined
    at file:///Users/bryan/Projects/rapid/node_modules/@pixi/assets/lib/_virtual/checkImageBitmap.worker.mjs:20:30
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

I’m not sure whether we need to switch to a different build of Pixi for node. (I also might be able to work around the issue another way, since we aren’t using the worker functionality here.)

Expected Behavior

No errors.

Steps to Reproduce

tbd

Environment

  • pixi.js version: e.g. 7.4.0
  • Browser & Version: e.g. Node v18.17.1

Possible Solution

No response

Additional Information

No response

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Comments: 15 (9 by maintainers)

Commits related to this issue

Most upvoted comments

I apologize for not considering Node.JS environment in that PR! I’ll fix this issue soon.

@notchris extract.canvas doesn’t work in Node. You need to use extract.pixels or extract.base64 instead.

I’m referencing the official example: https://github.com/pixijs/node, but that’s good to know. Should that be updated as well? I’m going to try out .pixels now!

@notchris extract.canvas doesn’t work in Node. You need to use extract.pixels or extract.base64 instead.

Thanks @bigtimebuddy , and sorry for the noise… I tracked it down to an unneeded import * as PIXI from 'pixi.js'; from some code that was expected to run headless.

pixi.js does not run natively in Node.js, it’s browser only. If you need to run in Node.js, you can use this project: https://github.com/pixijs/node