Skip to content

Support ESM forge.config.js #3350

Closed

Description

@mahnunchik

Pre-flight checklist

  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project uses.
  • I have searched the issue tracker for a feature request that matches the one I want to file, without success.

Problem description

As ESM will lended in electron 28 electron/electron#37535 (comment) so it is useful to have ESM support in forge.config.js

Proposed solution

ESM support ;)

Alternatives considered

I don't know any reason to not support ESM

Additional information

No response

Activity

  1. mahnunchik commented on Sep 18, 2023

    @mahnunchik
    ContributorAuthor
    Error [ERR_REQUIRE_ESM]: require() of ES Module /test-electron/forge.config.js from /test-electron/node_modules/@electron-forge/core/dist/util/forge-config.js not supported.
    Instead change the require of forge.config.js in /test-electron/node_modules/@electron-forge/core/dist/util/forge-config.js to a dynamic import() which is available in all CommonJS modules.

    According to the error message adding the ESM support should be pretty easy.

  2. mahnunchik commented on Sep 18, 2023

    @mahnunchik
    ContributorAuthor

    Monkey patch of this file makes ESM config works!

    const loaded = await import(path_1.default.resolve(dir, forgeConfig));
  3. sebbean commented on Jan 15, 2025

    @sebbean

    this worked for me!
    #3671 (comment)

    A work-around I found is calling the Forge cli command script's with something like tsx. So in your package.json add this...

    "scripts": {
    "start": "tsx node_modules/@electron-forge/cli/src/electron-forge-start",
    "package": "tsx node_modules/@electron-forge/cli/src/electron-forge-package",
    "make": "tsx node_modules/@electron-forge/cli/src/electron-forge-make",
    "publish": "tsx node_modules/@electron-forge/cli/src/electron-forge-publish"
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions