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

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.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 15

Most upvoted comments

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