electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.48k stars 514 forks source link

npx electron-forge import Error [ERR_REQUIRE_ESM] #3292

Open scbing opened 1 year ago

scbing commented 1 year ago

Pre-flight checklist

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

{
  "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.<anonymous> (D:\code\app\node_modules\@electron-forge\cli\dist\electron-forge.js:10:18) {
  code: 'ERR_REQUIRE_ESM'
    at Object.<anonymous> (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.<anonymous> (D:\code\app\node_modules\listr2\dist\index.cjs:126:32)
    at Object.<anonymous> (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

joezappie commented 1 year ago

Ever figure this out? Just switched npm to yarn and getting this when trying to start my electron app