electron / electron/forge

npx electron-forge import Error [ERR_REQUIRE_ESM]

Open
#3,292 1 comment 2 reactions 0 assignees View on GitHub
bug import maybe-fixed-in-next
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

Error [ERR_REQUIRE_ESM]: node_modules\listr2\dist\index.cjs not supported

### Electron version

v25.4.0

### Operating system

Windows 11 (22621.1992)

### Last known working Electron Forge version

_No response_

### Expected behavior

An error occurred while using electron forge.

Current version

```
PS D:\code\app> node -v
v19.2.0
PS D:\code\app> npm -v
9.8.1
PS D:\code\app> yarn -v
1.22.19
```

### Actual behavior

1. edit package.json
2. yarn
3. yarn add --dev @electron-forge/cli
4. yarn electron-forge import
5. npx electron-forge import

package.json
```json
{
"name": "nuxt-app",
"description": "my test electron app",
"private": true,
"author": {
"email": "xxx@qq.com",
"name": "scb"
},
"main": "electron/main.js",
"scripts": {
"build": "nuxt build",
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"start": "electron-forge start",
"package": "electron-forge package",
"make": "electron-forge make",
"publish": "electron-forge publish"
},
"devDependencies": {
"@electron-forge/cli": "^6.2.1",
"@electron-forge/maker-squirrel": "^6.2.1",
"@electron-forge/maker-zip": "^6.2.1",
"@nuxt/devtools": "latest",
"@types/node": "^18.17.1",
"electron": "^25.4.0",
"electron-squirrel-startup": "^1.0.0",
"nuxt": "^3.6.5"
}
}
```

```
PS D:\code\app> yarn electron-forge import
yarn run v1.22.19
$ D:\code\app\node_modules\.bin\electron-forge import
D:\code\app\node_modules\listr2\dist\index.cjs:126
var import_wrap_ansi = __toESM(require("wrap-ansi"), 1);
^

Error [ERR_REQUIRE_ESM]: require() of ES Module D:\code\app\node_modules\wrap-ansi\index.js from D:\code\app\node_modules\listr2\dist\index.cjs not supported.
at Object. (D:\code\app\node_modules\@electron-forge\cli\dist\electron-forge.js:10:18) {
code: 'ERR_REQUIRE_ESM'
at Object. (D:\code\app\node_modules\@electron-forge\cli\dist\electron-forge.js:10:18) {
code: 'ERR_REQUIRE_ESM'
}

Node.js v19.2.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```

--------------------

```
PS D:\code\app> npx electron-forge import
D:\code\app\node_modules\listr2\dist\index.cjs:126
var import_wrap_ansi = __toESM(require("wrap-ansi"), 1);
^

Error [ERR_REQUIRE_ESM]: require() of ES Module D:\code\app\node_modules\wrap-ansi\index.js from D:\code\app\node_modules\listr2\dist\index.cjs not supported.
Instead change the require of index.js in D:\code\app\node_modules\listr2\dist\index.cjs to a dynamic import() which is available in all CommonJS modules.
at Object. (D:\code\app\node_modules\listr2\dist\index.cjs:126:32)
at Object. (D:\code\app\node_modules\@electron-forge\cli\dist\electron-forge.js:10:18) {
code: 'ERR_REQUIRE_ESM'
}

Node.js v19.2.0
```

### Steps to reproduce

1. yarn
2. yarn add --dev @electron-forge/cli
3. yarn electron-forge import
4. npx electron-forge import

### 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.