Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

How to export Phaser with ES6 syntax


Yuki
 Share

Recommended Posts

I've just tried to import phaser.js along this MDN document.

But it raises errors no matter how the import statement is applied.

import Phaser from './phaser.js';
=> Uncaught SyntaxError: The requested module does not provide an export named 'default'
import {Phaser} from './phaser.js';
=> Uncaught SyntaxError: The requested module does not provide an export named 'Phaser'
import * as phaser from './phaser.js';
=> Uncaught TypeError: Cannot set property 'PIXI' of undefined

It seems phaser.js doesn't have the export statements.

So, could someone advise me how to add an export statement to phaser.js so that it can be imported by other modules?

Link to comment
Share on other sites

Search for a couple of boilerplates, there have been (at least) a couple of threads, try searching for Phaser boilerplate or Phaser module boilerplate or even Phaser ES6 boilerplate on the forums here.

Personally, I couldn't get it to work cleanly and stopped fighting with it and accepted that the Phaser object is a global, this has the advantage that any plugins you want to work will work without issue i.e. you're using it as intended rather than trying to fight with it to get it to work differently.

Link to comment
Share on other sites

Thanks for your reply.

I searched some boilerplates you mentioned.

And I found phaser-es6-webpack seems good to me since it has ES6 syntax and provides a kind of convention of phaser game. And also, the project seems still active.

I would explore this and if I feel it too complex, I shall take Phaser global as you recommended. Thanks a lot!

Link to comment
Share on other sites

  • 11 months later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...