raddevus
raddevus

Reputation: 9077

Why does this unhandled rejection occur inside electron forge when running snapcraft on Ubuntu?

Note: This is not a duplicate of An unhandled rejection has occurred inside Forge: Error: Could not find any Electron packages in devDependencies

The answer to that one is to add author and description tags to the package.json and I have those added already.

Here are the details

Attempting to Build Snap Package Using Elecron Forge

  1. I have my forge.config.js set up in my project and I can build all other release packages: deb,rpm, windows, mac (zip & dmg)
  2. I am now attempting to get electron forge to build the snap package using @electron-forge/maker-snap (npm package here). This is the one referenced officially at the electron forge docs here.
  3. I run $ npm run make to fire the command -- the official way to do that for electron projects.
  4. I created an entire new target directory, cloned my code into it and tried it from there too but it still fails the same way.

Here's what it looks like when it runs and fails:

electron forge run and fail

Here's the failure info as text:

An unhandled rejection has occurred inside Forge:
Error: Command failed with a non-zero return code (2):
/usr/bin/snapcraft snap --output=/home/raddev/dev/electron/CYaPass-Electron/out/make/snap/x64/cyapass_1.4.4_amd64.snap
at ChildProcess.<anonymous> (/home/raddev/dev/electron/CYaPass-Electron/node_modules/@malept/cross-spawn-promise/dist/src/index.js:99:24)
    at ChildProcess.emit (node:events:514:28)
    at ChildProcess.emit (node:domain:489:12)
    at maybeClose (node:internal/child_process:1105:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5)

It Successfully Builds the App

It also successfully packages it up as a deb but then it fails to package it as a snap.

What I've Tried

  1. rm -rf out to delete out folder (target build directory under project) (so that the npm process will create the direct and have owner access to it again -- in case it failed for some reason.
  2. All manner of config values in the forge.config.js file for this installer.
  3. Tried manually running snapcraft command line but I don't have the yaml that the packager creates.

What Is Really Failing

The real failure that is occurring is in the call to the snapcraft app on my machine. I checked the version it is snapcraft 7.5.2

Here's the command it is failing on:

/usr/bin/snapcraft snap --output=/home/raddev/dev/electron/CYaPass-Electron/out/make/snap/x64/cyapass_1.4.4_amd64.snap

I've even examined the target code in the npm library (node_modules/@malept/cross-spawn-promise/dist/src/index.js:99:24) but that is just where the exception is thrown

Down the Rabbit Hole

After a lot of research and failed attempts I found a command which would allow me to point at my linux-based electron app build and run npx to fire up snapcraft. Found the command here.

npx electron-installer-snap --src=out/myappname-linux-x64

When I ran that I got a similar error that I was previously receiving but finally got some additional information.

npx electron-installer-snap --src=. Starting Snapcraft 7.5.2
Logging execution to '/home/raddev/.local/state/snapcraft/log/snapcraft-20230905-112449.770165.log'

You need 'multipass' set-up to build snaps: https://multipass.run.

I had no idea what multipass was so I searched web and found it here. Then I ran the install command: sudo snap install multipass

After that I attempted the command again, but I was still getting errors:

npx electron-installer-snap --src=.

Starting Snapcraft 7.5.2
Logging execution to '/home/raddev/.local/state/snapcraft/log/snapcraft-20230905-113958.477233.log' Build environment is in unknown state, cleaning first. info failed: cannot connect to the multipass socket launch failed: cannot connect to the multipass socket An error occurred with the instance when trying to launch with 'multipass': returned exit code 2. Ensure that 'multipass' is setup correctly and try again.

Different Results After Rebooting (after install of Multipass)

I rebooted my machine and tried again. Here's the output:

Starting Snapcraft 7.5.2                                                       
Logging execution to '/home/raddev/.local/state/snapcraft/log/snapcraft-20230905-122819.559201.log'                                                            
Build environment project directory changed from '/tmp/electron-snap--12098-gH68rJiHPL7T', cleaning first.
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
debconf: delaying package configuration, since apt-utils is not installed
update-alternatives: using /usr/lib/shim/shimx64.efi.signed.latest to provide /usr/lib/shim/shimx64.efi.signed (shimx64.efi.signed) in auto mode
find: ‘’: No such file or directory
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-4.15.0-213-generic
Warning: couldn't identify filesystem type for fsck hook, ignoring.
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/40-force-partuuid.cfg'
Sourcing file `/etc/default/grub.d/50-builddimg-settings.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-213-generic
Found initrd image: /boot/initrd.img-4.15.0-213-generic
Found linux image: /boot/vmlinuz-4.15.0-212-generic
Found initrd image: /boot/initrd.img-4.15.0-212-generic
Adding boot menu entry for EFI firmware configuration
done
mesg: ttyname failed: Inappropriate ioctl for device
debconf: delaying package configuration, since apt-utils is not installed
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
mesg: ttyname failed: Inappropriate ioctl for device
Source path "/tmp/electron-snap--17336-k666maUgfaKI" does not exist
An error occurred with the instance when trying to mount with 'multipass': returned exit code 1.
Ensure that 'multipass' is setup correctly and try again.
/home/raddev/dev/electron/CYaPass-Electron/node_modules/@malept/cross-spawn-promise/dist/src/index.js:99
                reject(new ExitCodeError(cmd, args, code, stdout, stderr));
                       ^

ExitCodeError: Command failed with a non-zero return code (2):
/usr/bin/snapcraft snap --output=/home/raddev/dev/electron/CYaPass-Electron/out/CYaPass-linux-x64/cyapass_1.4.4_amd64.snap
    at ChildProcess.<anonymous> (/home/raddev/dev/electron/CYaPass-Electron/node_modules/@malept/cross-spawn-promise/dist/src/index.js:99:24)
    at ChildProcess.emit (node:events:514:28)
    at maybeClose (node:internal/child_process:1105:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5) {
  cmd: '/usr/bin/snapcraft',
  args: [
    'snap',
    '--output=/home/raddev/dev/electron/CYaPass-Electron/out/CYaPass-linux-x64/cyapass_1.4.4_amd64.snap'
  ],
  stdout: '',
  stderr: '',
  code: 2
}

I am definitely stuck down the rabbit hole. I'm assuming this is just one of those things you cannot run on Ubuntu 22.04.2 LTS.

Tried On Pure Debian -- Same Failure I installed Debian (5.10.179-1) on VirtualBox and spun it up. I installed all of the dependencies (node, npm, Snapcraft, etc.) and cloned my project down and ran npm run make All of the failures were exactly the same.

This is not a valid way to build a snap -- I'm guessing that no one has ever tried this. Good luck to all in the future who want to try it.

Here are the errors (can't copy from VM so I had to take a snapshot):

debian failure, same as ubuntu

Upvotes: 0

Views: 999

Answers (1)

raddevus
raddevus

Reputation: 9077

I followed the docs for creating a snap using the snapcraft utility directly.

My snapcraft.yaml was based upon the sample one and looked like the following:

name: cyapass # you probably want to 'snapcraft register <name>'
base: core22 # the base snap is the execution environment for this snap
version: '1.44' # just for humans, typically '1.2+git' or '1.3.2'
summary: Never type, memorize or make up  a password again.  # 79 char long summary
description: |
  C'YaPass generates your passwords every time so they are never stored anywhere.
  
grade: stable # must be 'stable' to release into candidate/stable channels
confinement: strict # use 'strict' once you have the right plugs and slots

parts:
  cyapass-tar:
    # See 'snapcraft plugins'
    source: autotools
    plugin: ./cyapass.tar.gz

NOTE: The base: core22 is important here.

I ran snapcraft which should build the snap, but it threw an error. I got the following error:

plugin not registered

I found this explanation of why it fails.

So apparently, it will not run on Ubuntu 22.0.4.2 LTS.
It's been over 1 year since they've made any notes about that problem.

Can anyone build a snap package? I'm not sure.

I tried hacking the value and setting it to core20 (also a valid base). However, that fails further along in the system (after multipass runs) so there doesn't seem to be any workaround.

For now, it looks like to me...You can't get there from here.

Upvotes: 0

Related Questions