PixiJS fails to bootstrap when using only named imports
See original GitHub issueExpected 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.
- Document the requirement to perform
import 'pixi.js';
specifically when using named imports in the new setup (@pixi/*
). - Have a dedicated package with side-effects for setting up pixi.js (e.g.
@pixi/init
). - Do (2) automatically from core pixi packages, specifically those that require the setup (
@pixi/app
).
Steps to Reproduce
- Create an empty project. For example, using a vitejs typescript template
- Add pixi.js as package dependency
- Use the sample from earlier
- Run the app
- If correct you will observe “Current Behavior”
Environment
pixi.js
version:PixiJS 6.1.3 - ✰ WebGL 2 ✰
- Browser & Version: Chrome 95
- OS & Version: Win10
- Running Example: https://codesandbox.io/s/happy-cloud-fbzk6?file=/src/index.ts
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try this:
Not this:
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.
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.