electron-builder
electron-builder copied to clipboard
Packaging for DMG throws an module-not-found error
- 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.
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.
Going to version 22.13.1 fixed this issue for me.
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
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"
}
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
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
I am also blocked by this, I tried both of these suggestions:
- 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.
- Downgrade to electron-builder v22.13.1 and I got the same error about the missing cli-truncate package
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.
it worked for me:
-
npm install [email protected] -D
-
npm uninstall cli-truncate
- Check if
cli-truncate
exists inpackage.lock.json
file, ifcli-truncate
exists, then your dependencies are fixed
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.
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
Get same issue on github action. runs-on: macos-latest
Here is my version.
"electron": "^15.3.1",
"electron-builder": "^23.3.3",