Yuki

How to export Phaser with ES6 syntax

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?

Share this post


Link to post
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.

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.