electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.68k stars 1.74k forks source link

Packaging for DMG throws an module-not-found error #6471

Open icabetong opened 2 years ago

icabetong commented 2 years ago

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.

gmpinder commented 2 years ago

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] > lightsaber-systems-designer@0.6.0-beta.1 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.

kdh6429 commented 2 years ago

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

rogeriorc commented 2 years ago

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"
  }
mmaietta commented 2 years ago

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

qishibo commented 2 years ago

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

rehanvdm commented 2 years ago

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 commented 2 years ago

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.

lyswhut commented 2 years ago

Try the following solutions, it worked for me:

Solution 1:

  1. Remove node_modules directory and package-lock.json file
  2. npm install
  3. Check if cli-truncate exists in package.lock.json file, if cli-truncate exists, then your dependencies are fixed
  4. If it does not work for you, try solution 2

Solution 2:

  1. npm install cli-truncate@2.1.0 -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
stale[bot] commented 2 years ago

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.

gaccawi commented 2 years ago

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

zhengyangliu commented 2 years ago

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

Here is my version.

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