pixijs / pixi-react

Write PIXI apps using React declarative style
https://pixijs.io/pixi-react/
MIT License
2.24k stars 172 forks source link

Bug: ReferenceError: Worker is not defined #475

Closed Vlad7is7lav closed 2 months ago

Vlad7is7lav commented 4 months ago

Current Behavior

When I start (npm run dev) in next.js I get the error ReferenceError: Worker is not defined at Object. (S:\My Projects\spores\node_modules\@pixi\assets\lib_virtual\checkImageBitmap.worker.js:22:30)

I tried to change next.config.js with next code if (!isServer) { config.module.rules.push({ test: /pixi\.js$/, use: [ { loader: 'worker-loader', options: { inline: true, fallback: false }, }, ], }) } but it didn't help me.

How can I solve this problem? Please, help me anybody :(

Expected Behavior

Run application

Steps to Reproduce

`import { FC, useState, useEffect } from 'react' import s from './GamePage.module.scss' import { Stage, Text, Graphics } from "@pixi/react";

interface GamePage {}

export const GamePage: FC = () => {

const draw = (g:any) => { g.beginFill(0x0033cc, 1) g.drawRect(250, 150, 150, 120) g.endFill() }

return (

<div className={s.wrapper}>

  <div className={s.main}>

  <Stage
    width={400}
    height={400}
    renderOnComponentChange={true}
    options={{ antialias: true, backgroundAlpha: 0 }}
  />
  <Graphics draw={draw} />

  </div>
</div>

) }`

Environment

Possible Solution

No response

Additional Information

No response

alanwong22 commented 4 months ago

Same error

@pixi/react: 7.1.0 pixi.js: 7.2.4 react: 18.2.0 react-dom: 18.2.0

Chrome 122.0.6261.94

Zyie commented 3 months ago

Hey, this should be fixed in the next release of pixi

https://github.com/pixijs/pixijs/pull/10227

morses-code commented 3 months ago

@Zyie - is this fix only going to be in v8? I was hoping to avoid an upgrade right now.

Zyie commented 3 months ago

Sorry, should have clarified, it will be fixed in the next v7 release We already have the fix in v8

Zyie commented 2 months ago

Hey, pixi 7.4.2 should have solved this

https://github.com/pixijs/pixijs/releases/tag/v7.4.2

let me know if you still have issues and we can reopen this one