"npm ERR! code ENOTCACHED" - npm install problem with nodejs plugin

Hi,

On the Mozilla IoT team we’re trying to create a snap of our WebThings Gateway application which is built around a web server written in Node.js.

Following this tutorial we’ve got as far as the snapcraft prime step (snapcraft.yaml) but we’re having a problem with npm.

When the nodejs plugin tries to execute:

$ /root/parts/webthings-gateway/npm/bin/npm install --unsafe-perm --offline --prod

It fails with the error:

npm ERR! code ENOTCACHED
npm ERR! request to https://registry.npmjs.org/@fluent%2fbundle failed: cache mode is 'only-if-cached' but no cached response available.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-12-02T19_34_00_110Z-debug.log
Failed to run '/root/parts/webthings-gateway/npm/bin/npm install --unsafe-perm --offline --prod' for 'webthings-gateway': Exited with code 1.
Verify that the part is using the correct parameters and try again.

We have started to look at overriding the build step with override-build to run npm install with less caching, but it seems like that shouldn’t be necessary just to install the npm dependencies.

Any tips on how to make npm happy?

Note: We are using snapcraft 3.9, installed with $ sudo snap install --candidate snapcraft because with the current released version we got a different error.

Thanks

1 Like

I faced same issue today, Am using snapcraft, version 3.11 ,
multipass 1.2.0 & multipassd 1.2.0 on my machine and getting same error while using nodejs plugin of snapcraft.

My part definition looks like this;

parts:
   node:
     plugin: nodejs
     nodejs-version: 12.16.3
     nodejs-package-manager: npm

Output of npm while package install operation:

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.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-05-26T19_34_32_910Z-debug.log
Failed to run ‘/root/parts/node/npm/bin/npm install --unsafe-perm’ for ‘node’: Exited with code 1.
Verify that the part is using the correct parameters and try again.

Please let me know if i need to add something else to make this work.
Thanks

I have the exact same error.

Have you found a solution to this problem ?

Unfortunately this issue is still ongoing. In the past I found --use-lxd resolved the issue, but it didn’t work today

yep, hitting the same problem :frowning:

(base) chris@pop-os:~/projects/cli-worm$ snapcraft --version
snapcraft, version 4.4.2

With either snapcraft or snapcraft --use-lxd, my build ends in failure with:

/root/parts/cli-worm/npm/bin/npm install --unsafe-perm --offline --prod
npm ERR! code ENOTCACHED
npm ERR! request to https://registry.npmjs.org/async failed: cache mode is 'only-if-cached' but no cached response available.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-11-26T19_51_30_674Z-debug.log
Failed to run '/root/parts/cli-worm/npm/bin/npm install --unsafe-perm --offline --prod' for 'cli-worm': 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.

I’m guessing there’s some reason it can’t talk to the network; though, it had no problem downloading the required version of node.

My snapcraft.yml looks like:

name:  cli-worm
base: core18
version: '0.2.0'
summary:  an epub reader for the command line
description: |
  A simple command line ncurses style interface for reading epubs

grade: stable
confinement: strict
apps:
  cli-worm:
    command: env LC_ALL=C.UTF-8 cli-worm # set LC_ALL env value when running to properly display utf8 characters
    plugs:
      - home
      - removable-media

parts:
  cli-worm:
    source: .
    plugin: nodejs
    nodejs-version: 10.19.0
    nodejs-package-manager: npm
    stage-packages:
      - w3m # used to render xhtml to cli safe text

Anyone found a workaround for this?