phaserjs / phaser-editor-issues

Phaser Editor's bug tracker.
0 stars 0 forks source link

Allow /* START/END-USER-IMPORTS */ without Auto Import option #15

Open riprsa opened 2 months ago

riprsa commented 2 months ago

On Next.js 14.2.1 + App Router, with Auto Import option on for a scene, one could get the warning Attempted import error: 'phaser' does not contain a default export (imported as 'Phaser'). While this warning does not stop the app from compiling, it is pretty annoying. To remove it, one needs to change the line import Phaser from 'phaser'; to import { Phaser } from 'phaser';.

However, because the Editor hardcodes the former, one cannot use the option Auto Import. Without this option, any imports should be written above the compiled code (above the line /* START OF COMPILED CODE */), otherwise Editor removes them. But, sadly, with Auto Import turned on, one cannot use the block /* START-USER-IMPORTS */-/* END-USER-IMPORTS */, which structures the code a bit nicer.

Examples:

// Auto Import is on
/* START OF COMPILED CODE */
import Phaser from 'phaser'; // << warning! Phaser Editor added this line ❌
/* START-USER-IMPORTS */
// ...
import { EventBus } from "../EventBus"; // Phaser Editor does not remove it ✅
/* END-USER-IMPORTS */
...
// Auto Import is off
/* START OF COMPILED CODE */
// << no warning-generating line, Phaser Editor does not add it ✅
/* START-USER-IMPORTS */
import { EventBus } from "../EventBus"; // Phaser Editor will remove it on compilation ❌
// ...
/* END-USER-IMPORTS */
...

IMO, such duality is unnecessary. If Phaser Editor will recognise and respect START/END-USER-IMPORTS always, then it would be a bit easier to use and comprehend. So, it would be great to have something like that:

// Auto Import is off
/* START OF COMPILED CODE */
// << no warning-generating line, Phaser Editor does not add it ✅
/* START-USER-IMPORTS */
import { Phaser } from "phaser"; // If one wants to have explicit import
import { EventBus } from "../EventBus"; // Phaser Editor does not remove it ✅
// ...
/* END-USER-IMPORTS */
...
tomas-correia commented 1 month ago

Phaser Editor removes your imports in USER-IMPORTS with Auto Import turned off because it is inside the COMPILED CODE block. You can just add your imports before this block (at the very top of the file) and the editor won't remove them.

Either way, I also rarely enable auto-import because of that Phaser import warning. I think another solution to this issue would simply be fixing the Phaser import, which is invalid for some weird reason.

I get that some files having USER-IMPORTS blocks and others not could feel like breaking a pattern. To be honest, I'm not too sure why USER-IMPORTS exist when you can just add them before the COMPILED CODE block