phaser icon indicating copy to clipboard operation
phaser copied to clipboard

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

Open totty90 opened this issue 12 years ago • 15 comments

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.

totty90 avatar Jul 16 '14 19:07 totty90

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

photonstorm avatar Jul 16 '14 21:07 photonstorm

thanks for your fast reply

totty90 avatar Jul 16 '14 22:07 totty90

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

totty90 avatar Dec 03 '14 14:12 totty90

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

cwramsey avatar Jan 07 '15 02:01 cwramsey

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;

totty90 avatar Jan 08 '15 00:01 totty90

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!

ghost avatar Jan 24 '15 21:01 ghost

The phaser-wrapper.js content is this:

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

totty90 avatar Jan 25 '15 18:01 totty90

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!

ghost avatar Jan 27 '15 21:01 ghost

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

photonstorm avatar Feb 09 '15 20:02 photonstorm

@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)

totty90 avatar Feb 10 '15 11:02 totty90

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

ghost avatar Feb 10 '15 19:02 ghost

Getting this with 2.4.3 using npm and webpack.

devchakraborty avatar Sep 05 '15 19:09 devchakraborty

https://github.com/photonstorm/phaser/issues/1974#issuecomment-134222165

photonstorm avatar Sep 05 '15 23:09 photonstorm

Thanks.

devchakraborty avatar Sep 06 '15 00:09 devchakraborty

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

bevinhex avatar Sep 14 '16 20:09 bevinhex