phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.2k stars 7.1k forks source link

setting default export in Phaser3 #6780

Closed wooseok123 closed 7 months ago

wooseok123 commented 7 months ago

I'm using Phaser3 in next.js environment. It means, i'm using es6 when i import Phaser, not using es5(require)

Everytime i import Phaser and build it, it cause an import error message.

/* error message */
Attempted import error: 'phaser' does not contain a default export (imported as 'Phaser').

So i think it can be resolved by adding a single line of code.

/* before phaser.d.ts */
declare module 'phaser' {
    export = Phaser;
}
/* after phaser.d.ts */
declare const phaser : Phaser;

declare module 'phaser' {
    export = phaser;
}

By declaring a varaible phaser, Phaser could be used as if it is a default export in es6 syntax. It could be also available for es5. But i found that phaser type files are automatically generated by tsgen, so i don't know how i can add this line.

Or this import error could be triggered by a next.js environment?

Phaser Version: 3.80 Operating system: window Browser: chrome

photonstorm commented 7 months ago

We provide an ESM version of Phaser, but you have to import it specifically. See here for details: https://github.com/phaserjs/phaser/blob/master/changelog/3.60/ESMSupport.md

wooseok123 commented 7 months ago

We provide an ESM version of Phaser, but you have to import it specifically. See here for details: https://github.com/phaserjs/phaser/blob/master/changelog/3.60/ESMSupport.md

Thank you! It works on me. Then, the esm version of Phaser is supported but it's not a default system for now?

photonstorm commented 7 months ago

We provide an ESM version of Phaser, but you have to import it specifically. See here for details: https://github.com/phaserjs/phaser/blob/master/changelog/3.60/ESMSupport.md

Thank you! It works on me. Then, the esm version of Phaser is supported but it's not a default system for now?

Correct. Part of the work we're doing at the moment is upgrading the whole codebase to ES6 so it's native ESM, but this is not yet finished. Please follow our Dev Logs (in the Phaser World newsletter) to track progress. We shouldn't be far out now. This will form the basis of the 4.0.0 release.