Snapcraft Fails to Determine Source Type with `plugin: npm` on Ubuntu 24.04

I am encountering difficulties building a snap for my Node.js application using Snapcraft on Ubuntu 24.04. The build consistently fails with the following error:

Failed to pull source: unable to determine source type of '.'.
Failed to execute pack in instance.
Recommended resolution: Run the same command again with --debug to shell into the environment if you wish to introspect this failure.
Full execution log: '/home/lcio/.local/state/snapcraft/log/snapcraft-20240717-173300.974803.log'

Steps to Reproduce:

  1. Create a new Node.js project directory.
  2. Create a server.js file containing your Node.js server code.
  3. Create a package.json file listing your project’s dependencies.
  4. Create a snapcraft.yaml file with the following content:
name: printerkiosk
base: core22
version: '0.1' 
summary: Printer Kiosk Server Snap
description: |
  This is a snap package for a Node.js server powering a printer kiosk.

confinement: strict

apps:
  printerkiosk:
    command: node $SNAP/server.js   
    daemon: simple
    environment:
      NODE_ENV: production
    plugs:
      - usb

plugs:
  usb:
    interface: usb
    target: printerkiosk
    attributes: raw-usb
    allow-auto-connect: true

parts:
  printerkiosk:
    plugin: npm
    source: .
    source-type: directory
    npm-include-node: true 
    npm-node-version: 18.16.1 
    build-packages:
      - build-essential
      - libudev-dev
  1. Run snapcraft clean (optional).
  2. Run snapcraft.

Expected Behavior:

Snapcraft should successfully build the snap without errors.

Actual Behavior:

The build fails with the “unable to determine source type” error.

Environment:

  • Operating System: Ubuntu 24.04
  • Snapcraft Version: 8.3.1
  • Node.js Version: v18.19.1
  • npm Version: 9.2.0

Additional Information:

  • I have confirmed that the server.js, package.json, and package-lock.json files are in the correct location (/home/lcio/mysnaps/printerkiosk/snap).
  • The files have read/write permissions: -rw-rw-r--
  • I have tried running snapcraft clean and rebuilding multiple times.
  • I have verified that my user is a member of the lxd group and that the LXD socket has the correct permissions.

Log File Excerpts:

2024-07-17 17:33:06.731 Failed to pull source: unable to determine source type of '.'.
2024-07-17 17:33:06.736 Traceback (most recent call last):
...
craft_parts.sources.errors.InvalidSourceType: Failed to pull source: unable to determine source type of '.'.
...
2024-07-17 17:33:11.144 subprocess.CalledProcessError: Command '['lxc', '--project', 'snapcraft', 'exec', 'local:snapcraft-printerkiosk-on-amd64-for-amd64-304832', '--cwd', '/root/project', '--', 'env', 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin', 'CRAFT_MANAGED_MODE=1', 'DEBIAN_FRONTEND=noninteractive', 'DEBCONF_NONINTERACTIVE_SEEN=true', 'DEBIAN_PRIORITY=critical', 'snapcraft', 'pack', '--verbosity=brief', '--build-for', 'amd64']' returned non-zero exit status 1.

I hope this helps! Let me know if you have any other questions.

You can either drop source-type: directory or replace it with source-type: local.

Dropping it is probably easiest - Snapcraft can figure out source: . is a local source.

The list of supported source-types is listed here: https://snapcraft.io/docs/snapcraft-yaml-reference

1 Like