electron / electron/forge

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

Open
#3,608 1 comment 4 reactions 0 assignees View on GitHub
bug make maybe-fixed-in-next plugin/webpack
Dominant language
TypeScript
Stars
7.1k
Forks
641
Avg merge
3d 1h
Merged PRs (30d)
30

Description

### Pre-flight checklist

- [X] I have read the [contribution documentation](https://github.com/electron/forge/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [code of conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project uses.
- [X] 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.