question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PixiJS fails to bootstrap when using only named imports

See original GitHub issue

Expected Behavior

The following Pixi.JS sample should produce a black square, but instead the rendering does not seem to be performed at all.

import { Application } from '@pixi/app'

const app = new Application({width:100,height:100, backgroundColor: 0x000000});
document.body.appendChild(app.view);

This particular sample is part of https://github.com/kittykatattack/learningPixi#creating-the-pixi-application-and-stage. The tutorial itself is advertised on https://pixijs.com/tutorials/.

Current Behavior

The canvas for the app mounts, but it is blank and never renders the scene.

Possible Solution

I noticed that adding import 'pixi.js'; was sufficient to get the code to work.

  1. Document the requirement to perform import 'pixi.js'; specifically when using named imports in the new setup (@pixi/*).
  2. Have a dedicated package with side-effects for setting up pixi.js (e.g. @pixi/init).
  3. Do (2) automatically from core pixi packages, specifically those that require the setup (@pixi/app).

Steps to Reproduce

  1. Create an empty project. For example, using a vitejs typescript template
  2. Add pixi.js as package dependency
  3. Use the sample from earlier
  4. Run the app
  5. If correct you will observe “Current Behavior”

Environment

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bigtimebuddycommented, Oct 31, 2021

Try this:

import { Application } from 'pixi.js'

Not this:

import { Application } from '@pixi/app'

Importing the sub packages directly is fine, but there’s some “glue” code that needs to be imported to wire up all the plugins. Importing only app will not include these important bits. Check out https://pixijs.io/customize to see what the glue code looks like.

I suggest you import names exports from the pixi.js package instead.

0reactions
stale[bot]commented, Mar 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Loading a spritesheet in Pixijs does not work - Stack Overflow
The solution is to move spriteSheet.json with spriteSheet.png from assets to public folder. And set path images/spriteSheet.json (in ...
Read more >
Getting started with PixiJS and React: Create a canvas
Let's bootstrap a React app with create-react-app by running the ... The Stage component that we just imported contains the underlying code ...
Read more >
Cannot use import statement outside module in JavaScript
The SyntaxError: Cannot use import statement outside a module occurs when we use the ES6 Modules syntax in a script that was not...
Read more >
can't import the named export from default-exporting module ...
js Error: Can't import the named export 'Assignment'.'StatusChange' (imported as 'Assignment') from default-exporting module (only default export is available) ...
Read more >
Typescript, ES6 and treeshaking - Pixi.js
or am I just doing it wrong, and treeshaking already works with import * as PIXI from 'pixi.js'? Quick caveat: I'm new to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found