Please help with electron, require, and import

Hello all,

I’m usually the type to just go figure things out myself, but I’m dealing with layers of stuff I don’t fully understand, and I think I need help.

The things I don’t have a great understanding of are webpack/commonJS/imports/requires. I get the basics of them, but now that I have some code using import and some using require I don’t know how to resolve my problems. (I’ve been out of web dev for several years, so the massive stack of build tools stuff has gotten away from me a bit.)

I have a phaser game I built starting with the create-phaser-game repo https://github.com/phaserjs/create-game. This repo uses import statements everywhere and is webpack-based.

(You can play the game at https://bescarfed.com/)

I am trying to wrap it up in electron, as advised so I can make an executable (hopefully for Steam eventually), and I’m trying to copypasta-and-adapt the code in electron-boilerplate https://github.com/sindresorhus/electron-boilerplate. This repo uses require statements.

Now I’m stuck in this weird state where I’m getting an unhandled exception error from the node_module called electron-util telling me to change an import statement to a require statement. That doesn’t seem right, so I must have a problem somewhere else.

image

I tried switching out the requires in electron-main.js to imports but then I get this error:
image

Like I said, I’d normally go investigate myself and figure this out, but I’m honestly not even sure what to start researching or even where to start looking to get a better grasp on what’s happening here. Can anyone help me?

I’m honestly not even sure what pieces of information I would need to share to help me get this resolved, so if there are any questions, I’ll try to get back to you quickly.

Ideally, I’d like to be able to use separate script commands to build for web and build for electron.

I just set up a project with electron-vite, that sets everything up for you to use modern syntax including import, with the framework of your choice. Maybe that solves your problem?

There were some caveats to getting it up and running with Phaser, see my post here: