ERR! npm ERR! `npm ci` does not work for global packages npm

I’m attempting to build a snap for nativefier, and I’m having a ton of trouble getting it to successfully build. I’ve tried a lot of various ideas borrowed from forum posts here, and from examples of snapcraft.yaml files on GitHub. I’m really at a loss and could use an assist. I think this might be a fun snap for people to use.

Here’s the current (28 JAN 2022) version of my snapcraft.yaml:

name: nativefier
adopt-info: nativefier
summary: Nativefier is a command-line tool to easily create a “desktop app”
description: |
  Nativefier is a command-line tool to easily create a “desktop app” for any web site with minimal fuss. 
  Apps are wrapped by Electron (which uses Chromium under the hood) in an OS executable (.app, .exe, etc) usable on Windows, macOS and Linux.
  
license: MIT

base: core20
grade: stable
confinement: strict

assumes:
  - command-chain
  
environment:
  npm_config_prefix: '$SNAP_COMMON'
  npm_config_unsafe_perm: 'true'
  npm_config_global: 'true'
  
apps:
  nativefier: 
    command: nativefier
    command-chain: 
      - bin/homeishome-launch
    plugs:
      - network
      - home  
  
parts: 
  nativefier:
    plugin: npm
    npm-node-version: "16.13.2"    
    build-environment:
      - npm_config_global: 'true'
      - npm_config_prefix: '$SNAP_COMMON'
      - npm_config_unsafe_perm: 'true'      
    source: https://github.com/nativefier/nativefier.git
    source-type: git

    override-pull: |
      snapcraftctl pull
      snapcraftctl set-version "$(git describe --tags | sed 's/^v//' | cut -d "-" -f1)"
      
  homeishome-launch:
    plugin: nil
    stage-snaps:
      - homeishome-launch  

Here’s the current error I’m getting:

npm ERR!

command

sh -c cd app && npm ci && cd .. && npm run build

npm ERR! npm ERR! code ECIGLOBAL npm

ERR! npm ERR! `npm ci` does not work for global packages npm

ERR!

npm ERR!

npm ERR! A complete log of this run can be found in: npm ERR! npm ERR! /root/.npm/_logs/2022-01-28T20_24_00_963Z-debug.log

npm

Thanks in advance.

P.S. I’m using Fabrica to conduct these builds - because it’s awesome. Thanks @ogra!

1 Like

this one builds for me …

name: nativefier
adopt-info: nativefier
summary: Nativefier is a command-line tool to easily create a “desktop app”
description: |
  Nativefier is a command-line tool to easily create a “desktop app” for any web site with minimal fuss. 
  Apps are wrapped by Electron (which uses Chromium under the hood) in an OS executable (.app, .exe, etc) usable on Windows, macOS and Linux.
  
license: MIT

base: core20
grade: stable
confinement: strict

assumes:
  - command-chain
  
apps:
  nativefier: 
    command: bin/nativefier
    command-chain: 
      - bin/homeishome-launch
    plugs:
      - network
      - home  
  
parts: 
  nativefier:
    plugin: npm
    npm-node-version: "16.13.2"    
    source: https://github.com/nativefier/nativefier.git
    source-type: git
    override-build: |
      npm install --dev
      snapcraftctl build

    override-pull: |
      snapcraftctl pull
      snapcraftctl set-version "$(git describe --tags | sed 's/^v//' | cut -d "-" -f1)"
      
  homeishome-launch:
    plugin: nil
    stage-snaps:
      - homeishome-launch  
1 Like

Well, I don’t know what I’m doing wrong. :frowning:

+ snapcraftctl build
Building nativefier 
+ npm install --dev
/bin/bash: line 33: npm: command not found
Failed to run 'override-build': Exit code was 127.
Build failed

oops, sorry, i tested in an existing container where i had built an electron app before, try adding:

    build-snaps:
      - node/16/stable

to the nativefier part …

2 Likes

Thanks @ogra! It’s funny that I was suffering for days and you’re able to solve this problem in a couple of forum posts!

Oddly, Fabrica can build this snap without issue. But snapcraft.io cannot:

npm ERR! code 1
npm ERR! path /build/nativefier/parts/nativefier/build
npm ERR! command failed
npm ERR! command sh -c cd app && npm ci && cd .. && npm run build

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-01-29T00_36_00_405Z-debug.log
Failed to run 'override-build': Exit code was 1.

the actual error is likely a few lines above what you posted …

see:

… perhaps the workaround in there helps …