snapcraft's nodejs plugin does not refresh the global, user cache before installing dependencies

Bug #1660614 reported by Geoffroy Van Cutsem
This bug affects 3 people
Affects Status Importance Assigned to Milestone

Bug Description

When using the nodejs plugin of snapcraft, it installs the required package and its dependencies using the "--cache-min" parameter (see [1]). That basically means the npm cache will not be refreshed before attempting the operation and that can result in errors if the following scenario occurs:
- Your snap depends on the nodejs "foo" module, initially version 1.
- Version 1 of your snap depends on "foo" version 1 and can successfully be built.
A few days/weeks later:
- You update your snap to version 2 and now require "foo" version 2
But now building your snap fails with an error indicating that "foo" version 2 is not available from the npm registry. That message is confusing because if you check the online npm registry, you will see that it is, in fact, available.

The error comes from the fact that 'npm' used an outdated version of the cache that is availabe (and was built before "foo" version 2 was available). For a more complete (and real) error message, see [2] below.

A manual workaround is to check the status of the npm cache on your build system (`npm outdated`) and update it (`npm update`) if needed.

It would be desirable to remove that option (or find a different mechanism in case snapcraft should also be able to operate offline).

[2] gvancuts@gvancuts-nuc:~/iot-rest-api-server$ snapcraft Preparing to pull meta-iot-web Pulling meta-iot-web From
 * branch master -> FETCH_HEAD
Already up-to-date.
Downloading 'node-v4.4.4-linux-x64.tar.gz'[===========================================================================================================================================================] 100% npm --cache-min=Infinity install npm ERR! Linux 4.4.0-59-generic npm ERR! argv "/home/gvancuts/iot-rest-api-server/parts/meta-iot-web/install/bin/node" "/home/gvancuts/iot-rest-api-server/parts/meta-iot-web/install/bin/npm" "--cache-min=Infinity" "install"
npm ERR! node v4.4.4
npm ERR! npm v2.15.1
npm ERR! code ETARGET

npm ERR! notarget No compatible version found: iotivity-node@'>=1.2.0-1 <2.0.0'
npm ERR! notarget Valid install targets:
npm ERR! notarget ["0.9.2-0","0.9.2-1","1.0.0-0","1.0.0-1","1.0.0-2","1.0.0-3","1.0.0-4","1.0.1-0","1.0.1-1","1.1.0-1","1.1.0-2","1.1.0-3","1.1.0-4","1.1.0-5","1.1.1-0","1.1.1-1","1.1.1-2","1.1.1-3","1.2.0-0"]
npm ERR! notarget
npm ERR! notarget This is most likely not a problem with npm itself.
npm ERR! notarget In most cases you or one of your dependencies are requesting npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'iot-rest-api-server'
npm ERR! notarget

npm ERR! Please include the following file with any support request:
npm ERR! /home/gvancuts/iot-rest-api-server/parts/meta-iot-web/src/npm-debug.log
Command '['/bin/sh', '/tmp/tmpmchipfnc', 'npm', '--cache-min=Infinity', 'install']' returned non-zero exit status 1

Tags: plugins
Revision history for this message
Leo Arias (elopio) wrote :

From Stephen: Consider having the nodejs plugin support per project .npmrc so users can set cache options themselves rather than set via args in the plugin.

tags: added: plugins
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers