Skip to content

Must use import to load ES Module: webpack.main.config.ts #3608

Open

Description

@yusangeng

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 bug that matches the one I want to file, without success.

Electron Forge version

7.4.0

Electron version

29.1.0

Operating system

WIndows 11(21H2)

Last known working Electron Forge version

Null

Expected behavior

The electron-forge make command successfully runs, packaging my project into an installer file.

Actual behavior

Error occured while running the electron-forge make command.

Must use import to load ES Module: mypath\webpack.main.config.ts
require() of ES modules is not supported.
require() of mypath\webpack.main.config.ts from
mypath\forge.config.cts 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
mypath\package.json.

Note: My forge config file has been renamed to forge.config.cts, but it still be recognized as an ES module file.

Steps to reproduce

  1. Init an electron-foge project
  2. set "type" field to "module"(Because my project depends a package which use "exports" field to export entries, so I think I should set "type" to "module").
  3. npm run make

Additional information

No response

Activity

  1. added
    plugin/webpack
    make
    on Jan 31, 2025
  2. added
    maybe-fixed-in-next
    on Jul 1, 2026
  3. hiSandog commented on Jul 15, 2026

    @hiSandog

    Renaming forge.config to .cts only changes the module mode of that file; the imported webpack.main.config.ts is still inside a type: module package scope, so the reported behavior is consistent with the error. A regression fixture with that exact combination would help validate the maybe-fixed-in-next label: ESM package, forge.config.cts, and a TypeScript webpack config loaded during make. It would also catch a fix that works for the Forge config but still uses require() for plugin config files.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmakemaybe-fixed-in-nextplugin/webpack

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions