Phaser: Getting ReferenceError: PIXI is not defined with the v2.0.6 in the v2.0.4 was ok.

Created on 16 Jul 2014  路  15Comments  路  Source: photonstorm/phaser

Line 11549 (PIXI.InteractionManager = PIXI.InteractionManager || function () {};)

if (typeof exports !== 'undefined') {
    if (typeof module !== 'undefined' && module.exports) {
        exports = module.exports = PIXI;
    }
    exports.PIXI = PIXI;
} else if (typeof define !== 'undefined' && define.amd) {
    define(PIXI); // <-- because of this PIXI turns undefined
} else {
    root.PIXI = PIXI;
}

I'm using require.js

Possible solution but NOT optimal:

Create a file "otherModules/phaser/phaser-wrapper.js" with this content:

// This exports Phaser to window.
require('phaserUnFixed');
// And then we return it here.
module.exports = Phaser;

Now in your webpack config in resolve.alias add those lines:

        phaserUnFixed        : "nodeModules/phaser/build/custom/phaser-arcade-physics.js",
        phaser               : "otherModules/phaser/phaser-wrapper.js",

This will make your app to load the phaser-wrapper.js file when you request phaser. This file requires the real phaser file which exports the global Phaser variable. Then the module is properly exported.

I've done the same for PIXI.

All 15 comments

Yes sorry about that, this is fixed in the dev branch - please grab 2.0.7 from there and test that.

thanks for your fast reply

Still getting in v2.2.0. With webpack you have the module therefore your PIXI lib will get exported to module.exports object instead.

Yep, I'm getting this in 2.2.2 as well.

So here is the solution:

resolve.alias:

        phaserUnFixed        : "nodeModules/phaser/build/custom/phaser-arcade-physics.js",
        phaser               : "otherModules/phaser/phaser-wrapper.js",

File: otherModules/phaser/phaser-wrapper.js

// This exports Phaser to window.
require('phaserUnFixed');
// And then we return it here.
module.exports = Phaser;

Getting this error with 2.2.2 with the bower install. Looking for a solution.

I tried totty90's solution but I cannot find a phaser-wrapper.js file in my bower_components

Looking for help immediately as this is for Global Game Jam!

The phaser-wrapper.js content is this:

// This exports Phaser to window.
require('phaserUnFixed');
// And then we return it here.
module.exports = Phaser;

you just copied what you said eariler to which I mentioned that it didn't work for me.

I resolved my issue by commenting out some lines that were calling for PIXI.

Thanks for your input totty90!

If someone would like to wrap-up any of these solutions into a PR then I'll happily merge them.

@photonstorm this is kind of webpack specific, I don't know how to fix it properly. But I think that the lib should use a standard way to export modules, because this is the only one that has problems. (1 in like 50 modules)

My problem occurred whilst trying to get the Simon example working with the latest version during Global Game Jam.

Getting this with 2.4.3 using npm and webpack.

Thanks.

Same here , tried to put phaser.min.js in 'client/libs' folder for meteor, didn't work, also tried to install using npm install phaser
import Phaser from 'phaser'
Still no luck

Was this page helpful?
0 / 5 - 0 ratings