I’ve been trying to make a project created via Electron Forge to work with ESM.
At this point, ESM is mostly a must, since required libraries are exporting only to ESM and using older libraries is not accepted. Also, I’d like to avoid hacks, forks, and weird imports (i.e. import-sync) to make them work in CommonJS.
So the current state is supposed to be that Electron supports ESM since v28.
Forge is a tool for packaging acquire from Electron (repo is in electron/forge) but the forge.config.ts
file doesn’t seem to like ESM imports…
An unhandled rejection has occurred inside Forge:
Error: Must use import to load ES Module: ~forge.config.ts
require() of ES modules is not supported.
require() of ~forge.config.ts from ~node_modules@electron-forgecoredistutilforge-config.js is an ES module file as it is a .ts file whose nearest parent package.json contains "type": "module" which defines all .ts files in that package scope as ES modules.
Instead change the requiring code to use import(), or remove "type": "module" from ~package.json.
tsconfig.json
configured like this (+ type: "module"
),
"module": "node16",
"moduleResolution": "node16",
"moduleDetection": "force",
seems to make everything work… but can’t start the Forge app.
on the other hand, having it like
"module": "commonjs"
"moduleResolution": "node",
it starts the Forge app, everything looks ok, it’s even able to import some ESM packages such as nanoid… but with others like electron-store the types are not recognized properly (like this problem)
So I guess the question is…
What’s the current state of Electron development? Are we in a world were nothing can be set to work perfectly anymore? Or am I missing some step here? I feel like I’ve tried most possible configurations…