layers: Unable to import
Hello there,
both… require('pixi-layers) …and… import {Stage, Layer} from ‘pixi-layers’, or import * as Layers from ‘pixi-layers’ …fails.
Uncaught ReferenceError: PIXI is not defined
I did import PIXI before the import call. import ‘pixi.js’ or import PIXI from ‘pixi.js’
I also tried require.
Nothing works… same error. The layers plugin is not compatible with cjs and es imports?
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 16
For those who have this issue here is an implementation of this “cheap” workaround that work for me.
in your webpack config:
with this script :
Here is cheap workaround for module support. This worked for my situation that using pixi-layers with webpack or rollup.
First, forking plugin. Then just add import statement at top of dist/pixi-layers.js.
When apply workaround above,
import * as PIXI from "pixi.js"beforeimport "pixi-layers"will work expected.About known workarounds…
import * as PIXI from "pixi.js"beforeimport "pixi-layers"by user is meaningless. That imports PIXI to user’s scope only. Alsowindow.PIXI = PIXI;workaround is incompatible with ES6 hoisting vehavior(It affects with rollup, babel, etc…). So, plugins should import pixi.js by themselves.