NPM github install failures

First: I haven’t worked with snapcraft for years and I’m really gratified to see how much the surrounding sites / app search have improved. I wish you the best on this project, it’s an inspired project

I’m trying to upgrade my package (polonium) with a few tweaks and fixes, but I’ve ran into a lot of trouble with repackaging the app.

To reproduce, run

git clone https://github.com/rgrannell1/polonium
cd polonium
npm i
snapcraft

which gives the error

/root/parts/polonium/npm/bin/yarn install --offline --prod
yarn install v1.16.0
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
error Can't make a request in offline mode ("https://codeload.github.com/rgrannell1/is/tar.gz/5a2f30473678c62903760e9259d7da82b6325ce2")
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Failed to run '/root/parts/polonium/npm/bin/yarn install --offline --prod' for 'polonium': Exited with code 1.
Verify that the part is using the correct parameters and try again.
Run the same command again with --debug to shell into the environment if you wish to introspect this failure.
An error occurred when trying to execute 'sudo -i env SNAPCRAFT_HAS_TTY=True snapcraft snap' with 'multipass': returned exit code 2.

The package it’s complaining about is an inner dependency installed from github

"is": "github:rgrannell1/is"

my configuration is

name:        polonium
grade:       stable
version:     v1.0.0
summary:     Polonium is a stateless password manager based on PBKDF2.
description: Polonium is a stateless password manager based on PBKDF2

confinement: "strict"

base: core18

apps:
  polonium:
    command: bin/polo

parts:
  polonium:
    source: .
    plugin: nodejs
    build-packages: ['libcurl4-openssl-dev']
    stage-packages: ['git']

Installing git seems to have help me overcome some errors, but not get the download to succeed.

Any ideas what I can do to fix this?
Thanks

Thank you for the kind words.

My initial suspicion is that yarn does not recurse through git declared dependencies. This diff which switches to npm and puts git in build-packages gets the build going:

diff --git a/snapcraft.yaml b/snapcraft.yaml
index 1c8a71f..08abb0d 100644
--- a/snapcraft.yaml
+++ b/snapcraft.yaml
@@ -16,5 +16,5 @@ parts:
   polonium:
     source: .
     plugin: nodejs
-    build-packages: ['libcurl4-openssl-dev']
-    stage-packages: ['git']
+    nodejs-package-manager: npm
+    build-packages: ['git', 'libcurl4-openssl-dev']

Thanks for your response,

Unfortunately that triggers an access problem instead upon npm install. I suspect the attempted process spawn during install is being blocked by user rights?

/root/parts/polonium/npm/bin/npm install
npm WARN deprecated circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
npm ERR! code EACCES
npm ERR! errno EACCES
npm ERR! syscall spawn
npm ERR! Error: spawn EACCES
npm ERR!     at ChildProcess.spawn (internal/child_process.js:313:11)
npm ERR!     at Object.exports.spawn (child_process.js:503:9)
npm ERR!     at promiseRetry (/root/parts/polonium/npm/lib/node_modules/npm/node_modules/pacote/lib/util/git.js:209:24)
npm ERR!     at /root/parts/polonium/npm/lib/node_modules/npm/node_modules/promise-retry/index.js:29:24
npm ERR!     at <anonymous>
npm ERR!  { Error: spawn EACCES
npm ERR!     at ChildProcess.spawn (internal/child_process.js:313:11)
npm ERR!     at Object.exports.spawn (child_process.js:503:9)
npm ERR!     at promiseRetry (/root/parts/polonium/npm/lib/node_modules/npm/node_modules/pacote/lib/util/git.js:209:24)
npm ERR!     at /root/parts/polonium/npm/lib/node_modules/npm/node_modules/promise-retry/index.js:29:24
npm ERR!     at <anonymous>
npm ERR!   stack: 'Error: spawn EACCES\n    at ChildProcess.spawn (internal/child_process.js:313:11)\n    at Object.exports.spawn (child_process.js:503:9)\n    at promiseRetry (/root/parts/polonium/npm/lib/node_modules/npm/node_modules/pacote/lib/util/git.js:209:24)\n    at /root/parts/polonium/npm/lib/node_modules/npm/node_modules/promise-retry/index.js:29:24\n    at <anonymous>',
npm ERR!   errno: 'EACCES',
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'spawn',
npm ERR!   parent: 'polonium' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-06-18T21_09_53_362Z-debug.log
Failed to run '/root/parts/polonium/npm/bin/npm install' for 'polonium': Exited with code 1.
Verify that the part is using the correct parameters and try again.
Run the same command again with --debug to shell into the environment if you wish to introspect this failure.
An error occurred when trying to execute 'sudo -i env SNAPCRAFT_HAS_TTY=True snapcraft snap' with 'multipass': returned exit code 2.

Edit:
Changing confinement didn’t seem to fix this

Ah, I might have not seen this as I was using snapcraft with --use-lxd, let me verify that and get back to you.

1 Like

I also have a snap that fails to build with yarn, but succeeds with npm. If built in a multipass container, the build fails with

npm ERR! fatal: failed to stat '/root/parts/appservice/src': Permission denied

whereas in an LXD container (I initially used --destructive, but now that I know --use-lxd is an option this also works) it succeeds.

I reran with LXD set up, and got

/root/parts/polonium/npm/bin/npm install
npm WARN deprecated circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
npm ERR! code 1
npm ERR! Command failed: /root/parts/polonium/install/usr/bin/git submodule update -q --init --recursive
npm ERR! git: 'submodule' is not a git command. See 'git --help'.
npm ERR! 

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-06-21T14_48_19_074Z-debug.log
Failed to run '/root/parts/polonium/npm/bin/npm install' for 'polonium': Exited with code 1.
Verify that the part is using the correct parameters and try again.

instead

Edit: Moving Git to a build package fixed this, though git should probably just be a dependency for the npm plugin by default

I’m running into problems with a different package and ran into more installation issues unfortunately. I’m getting the impression --offline is causing problems, but I’m not sure of the exact cause

(tried with both nodejs-package-manager: yarn and nodejs-package-manager: npm)

git clone "git@github.com:rgrannell1/kohl.git"
cd kohl && git checkout 332e2e2
snapcraft

success Wrote tarball to "rgrannell-kohl-0.1.0.tgz".
Done in 0.18s.
/root/parts/kohl/npm/bin/yarn install --offline --prod
yarn install v1.22.5
[1/4] Resolving packages...
[2/4] Fetching packages...
error Can't make a request in offline mode ("https://registry.yarnpkg.com/@types/ansi-styles/-/ansi-styles-3.2.1.tgz")
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Failed to run '/root/parts/kohl/npm/bin/yarn install --offline --prod' for 'kohl': Exited with code 1.
Verify that the part is using the correct parameters and try again.
Run the same command again with --debug to shell into the environment if you wish to introspect this failure.
sudo snapcraft --use-lxd 

/root/parts/kohl/npm/bin/yarn pack --filename rgrannell-kohl-0.1.0.tgz
yarn pack v1.22.5
success Wrote tarball to "rgrannell-kohl-0.1.0.tgz".
Done in 0.16s.
/root/parts/kohl/npm/bin/yarn install --offline --prod
yarn install v1.22.5
[1/4] Resolving packages...
[2/4] Fetching packages...
error Can't make a request in offline mode ("https://registry.yarnpkg.com/@types/ansi-styles/-/ansi-styles-3.2.1.tgz")
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
Failed to run '/root/parts/kohl/npm/bin/yarn install --offline --prod' for 'kohl': Exited with code 1.
Verify that the part is using the correct parameters and try again.

I just tried Snapcraft with --use-lxd from the edge channel and stable from today (4.3) using the specified commit and in both cases got:

Snapped kohl_v0.1.0_amd64.snap

What version of Snapcraft are you using?

Strange, I’m using 4.3 too

❯ snapcraft --version
snapcraft, version 4.3

❯ snap --version
snap 2.47.1+20.10.1
snapd 2.47.1+20.10.1
series 16
ubuntu 20.10
kernel 5.8.0-25-generic