electron-builder icon indicating copy to clipboard operation
electron-builder copied to clipboard

Packaging for DMG throws an module-not-found error

Open icabetong opened this issue 2 years ago • 11 comments

  • Electron-Builder Version: 22.14.5
  • Node Version: v14.18.1
  • Electron Version: 13.1.7
  • Electron Type (current, beta, nightly): current
  • Target: macOS

Packaging for macOS with DMG target throws an node module failed: cannot find module 'cli-truncate'. However, I tried to target as PKG and it successfully worked.

icabetong avatar Dec 04 '21 02:12 icabetong

I also ran into this issue after upgrading from 22.11.7 to 22.14.5 today. The stack trace was as follows:

[electron:build] > [email protected] electron:build /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer [electron:build] > electron-builder build --publish=always [electron:build] [electron:build] • electron-builder version=22.14.5 os=19.6.0 [electron:build] • loaded configuration file=/opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/electron-builder.json [electron:build] ⨯ Cannot find module 'cli-truncate' [electron:build] Require stack: [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/iconv-corefoundation/lib/errors.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/iconv-corefoundation/lib/native.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/iconv-corefoundation/lib/index.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/dmg-license/lib/Labels.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/dmg-license/lib/assembleLicenses.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/dmg-license/lib/index.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/dmg-builder/out/dmgLicense.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/dmg-builder/out/dmg.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/dmg-builder/out/dmgUtil.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/app-builder-lib/out/macPackager.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/app-builder-lib/out/packager.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/app-builder-lib/out/index.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/electron-builder/out/builder.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/electron-builder/out/cli/cli.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/electron-builder/cli.js failedTask=build stackTrace=Error: Cannot find module 'cli-truncate' [electron:build] Require stack: [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/iconv-corefoundation/lib/errors.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/iconv-corefoundation/lib/native.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/iconv-corefoundation/lib/index.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/dmg-license/lib/Labels.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/dmg-license/lib/assembleLicenses.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/dmg-license/lib/index.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/dmg-builder/out/dmgLicense.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/dmg-builder/out/dmg.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/dmg-builder/out/dmgUtil.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/app-builder-lib/out/macPackager.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/app-builder-lib/out/packager.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/app-builder-lib/out/index.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/electron-builder/out/builder.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/electron-builder/out/cli/cli.js [electron:build] - /opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/electron-builder/cli.js [electron:build] at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15) [electron:build] at Function.Module._load (internal/modules/cjs/loader.js:746:27) [electron:build] at Module.require (internal/modules/cjs/loader.js:974:19) [electron:build] at require (internal/modules/cjs/helpers.js:93:18) [electron:build] at Object. (/opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/iconv-corefoundation/lib/errors.js:4:21) [electron:build] at Module._compile (internal/modules/cjs/loader.js:1085:14) [electron:build] at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) [electron:build] at Module.load (internal/modules/cjs/loader.js:950:32) [electron:build] at Function.Module._load (internal/modules/cjs/loader.js:790:12) [electron:build] at Module.require (internal/modules/cjs/loader.js:974:19) [electron:build] at require (internal/modules/cjs/helpers.js:93:18) [electron:build] at Object. (/opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/iconv-corefoundation/lib/native.js:4:16) [electron:build] at Module._compile (internal/modules/cjs/loader.js:1085:14) [electron:build] at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) [electron:build] at Module.load (internal/modules/cjs/loader.js:950:32) [electron:build] at Function.Module._load (internal/modules/cjs/loader.js:790:12) [electron:build] at Module.require (internal/modules/cjs/loader.js:974:19) [electron:build] at require (internal/modules/cjs/helpers.js:93:18) [electron:build] at Object. (/opt/builds/nr7ZdCYE/0/wunker-bunker/lightsaber-systems-designer/node_modules/iconv-corefoundation/lib/index.js:6:18) [electron:build] at Module._compile (internal/modules/cjs/loader.js:1085:14) [electron:build] at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) [electron:build] at Module.load (internal/modules/cjs/loader.js:950:32)

Going to version 22.13.1 fixed this issue for me.

gmpinder avatar Dec 05 '21 20:12 gmpinder

Same issue running on github actions.

Building the Electron app… • electron-builder version=22.13.1 os=19.6.0 • artifacts will be published if draft release exists reason=CI detected • loaded configuration file=package.json ("build" field) • loaded parent configuration preset=react-cra • description is missed in the package.json appPackageFile=/Users/runner/work/por/por/package.json • author is missed in the package.json appPackageFile=/Users/runner/work/por/por/package.json ⨯ Cannot find module 'cli-truncate'

Same error below versions. • electron-builder version=22.13.1 os=20.6.0 • electron-builder version=22.14.5 os=20.6.0

kdh6429 avatar Jan 27 '22 07:01 kdh6429

I managed to avoid this error installing cli-truncate on my project...

  "devDependencies": {
    "cli-truncate": "2.1.0",
    "electron": "16.0.6",
    "electron-builder": "22.14.5",
    "electron-notarize": "1.1.1"
  }

rogeriorc avatar Jan 27 '22 16:01 rogeriorc

Would someone be willing to put together a sample project I can test this with? My project is unable to reproduce locally. Also happy to review a PR for fixing this. Setting up a local dev env is fairly simple too https://github.com/electron-userland/electron-builder/blob/master/CONTRIBUTING.md#to-setup-a-local-dev-environment

mmaietta avatar Jan 27 '22 20:01 mmaietta

npm install cli-truncate -D then npm uninstall cli-truncate worked for me.

this will add cli-truncate with optional: true to package-lock.json

qishibo avatar Jan 30 '22 01:01 qishibo

I am also blocked by this, I tried both of these suggestions:

  1. Install the cli-truncate package. Then I got an error about the package.json type field, commonjs/module. Setting the value to either did not work because then it broke other stuff with the same error message: require() of ES modules is not supported.
  2. Downgrade to electron-builder v22.13.1 and I got the same error about the missing cli-truncate package

rehanvdm avatar Feb 02 '22 21:02 rehanvdm

A whole can of worms on this thread where the creator of cli-truncate goes into detail about ESM/CJS and there is even a section for electron https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-import-esm-in-electron . Looks like you have to install the prev major version that was CJS first (same problem with the chalk repo btw).

Only after I went through that thread did I realize @rogeriorc pinned his version to 2.1.0, which is the prev version I am speaking about. That worked.

rehanvdm avatar Feb 02 '22 21:02 rehanvdm

it worked for me:

  1. npm install [email protected] -D
  2. npm uninstall cli-truncate
  3. Check if cli-truncate exists in package.lock.json file, if cli-truncate exists, then your dependencies are fixed

lyswhut avatar Feb 26 '22 06:02 lyswhut

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Apr 28 '22 03:04 stale[bot]

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

I had this issue myself today as well.

Electron: 13.6.6 Node: 14.20.0

gaccawi avatar Aug 04 '22 19:08 gaccawi

Get same issue on github action. runs-on: macos-latest

Here is my version.

"electron": "^15.3.1",
"electron-builder": "^23.3.3",

zhengyangliu avatar Oct 09 '22 14:10 zhengyangliu