node2nix icon indicating copy to clipboard operation
node2nix copied to clipboard

ENOTCACHED error from a git dependency when using lock file

Open ento opened this issue 6 years ago • 12 comments

node2nix version: c876bb8 (latest master as of this writing)
node version: 10.x example code: https://gist.github.com/ento/2962993d4dfdf2e0778d5b2f4c57948f

I'm using node2nix to install dependencies required to build a frontend app. My shell.nix (simplified) looks like:

let
  pkgs = import <nixpkgs> {};
  npmSources = import ./npm/default.nix { inherit pkgs; };
in
pkgs.mkShell {
  buildInputs = [
    npmSources.shell.nodeDependencies
  ];
}

One of the dependencies in package.json looks like:

"js-cookie": "js-cookie/js-cookie#d2724a87a29cbf7ee539452fb42b3e3a1aff95a8"

(This is not the actual dependency I'm using. This is a random package that I found that doesn't have a package-lock.json at the root of the repo. The GitHub dependency I'm using has a package-lock.json in its repo, which I thought might've had something to do with the error after reading #106. Turns out the error reproduces even with a repo without the lock file.)

node2nix is invoked like so:

node2nix --nodejs-10 -i package.json -l package-lock.json

When trying to use nix-shell with the shell.nix above, I get this error:

Adding metadata fields to: node_modules/js-cookie/package.json [email protected] /nix/store/68a1rghsdc7ki6n06i1nwc8jnk1gmaam-node-dependencies-enotcached-mvce-0.0.0/enotcached-mvce/node_modules/js-cookie
npm ERR! code ENOTCACHED
npm ERR! request to https://registry.npmjs.org/js-cookie failed: cache mode is 'only-if-cached' but no cached response available.

Workarounds I've found so far:

  • Don't use package-lock.json, or override the shell derivation with reconstructLock = true
  • Patch resolveDependencyVersion in node-env.nix so that it returns the GitHub URL shorthand and add git to buildInputs of shell.nix

The effect of patching resolveDependencyVersion seems to be that npm (or the underlying library) switches to use the 'git' fetcher instead of some other fetcher that tries to read the local cache. I'm not sure if that's in the right direction towards a fix, or if what I'm doing is entirely incorrect in the first place.

ento avatar Mar 11 '19 05:03 ento

I had ENOTCACHED

all I did to fix it was

npm uninstall node2nix -g 

npm i git+https://[email protected]/svanderburg/node2nix.git#c876bb8f8749d53ef759de809ce2aa68a8cce20e --global

for my point of view, it seems node2nix needs a new release?

hlolli avatar Mar 18 '19 02:03 hlolli

I'm also facing this issue. Is there any bug preventing a new release?

jacereda avatar Mar 19 '19 11:03 jacereda

I tried current master and it seems the error is still present in my case :(

jacereda avatar Mar 19 '19 11:03 jacereda

And the repro posted by @ento also fails for me.

jacereda avatar Mar 19 '19 11:03 jacereda

@hlolli I'm using the same verison/sha and it still reproduces for me. It's possible your case is covered by this fix for another issue about the ENOTCACHED error, which isn't released to the npm registry yet.

ento avatar Mar 20 '19 07:03 ento

A workaround (in my case) is sed -i -e 's/dontNpmInstall ? false/dontNpmInstall ? true/g' node-env.nix

jacereda avatar Mar 22 '19 23:03 jacereda

@jacereda workaround also works in my case (compiling zigbee2mqtt deps).

oneingan avatar May 02 '19 10:05 oneingan

I think I manage to solve the problem. After digging through the internals of NPM for quite some time, I think this revision should fix it: 5bea6e555c7a73a72f9013ec49b98a8c76d0b94c

It seems that newer versions of NPM have become much more strict.

To give it a try, try to install the latest development version of node2nix.

svanderburg avatar May 31 '19 20:05 svanderburg

node2nix 1.7.0 contains preliminary git sub module support now.

svanderburg avatar Jun 05 '19 22:06 svanderburg

Trying to compile zigbee2mqtt master with 1.7.0 but same problem. Without @jacereda workaround Im getting:

$ node2nix --nodejs-10
(...)
OK
$ nix-build -A package
(...)
npm ERR! code ENOTCACHED                                                                                                                                                                                           
npm ERR! request to https://registry.npmjs.org/serialport 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!     /build/.npm/_logs/2019-06-15T23_31_05_723Z-debug.log                                                                                                                                                  
builder for '/nix/store/jlxj58s2sq8q2b5vgj5kj986gy2h8qsb-node_zigbee2mqtt-1.4.0.drv' failed with exit code 1                                                                                                       
error: build of '/nix/store/jlxj58s2sq8q2b5vgj5kj986gy2h8qsb-node_zigbee2mqtt-1.4.0.drv' failed

with workaround ends succesfully.

oneingan avatar Jun 15 '19 23:06 oneingan

If anyone ever stumbles upon the same issue or wants to reproduce this: @jacereda workaround is also needed for @aws-amplify/cli, in which case @aws-cdk/cloud-assembly-schema cannot be found.

The error only occurs for versions including 4.51.0 and above (I've tested 4.52.0,5.0.0,5.6.0,6.1.0,6.1.1). Older versions (e.g. 4.45.0,4.50.0) work out of the box.

Staff-d avatar Oct 06 '21 17:10 Staff-d

Thank you @jacereda for this workaround. Out of nowhere, I've just run into this issue and your fix resolved the issue. This had happened for me on @prettier/plugin-ruby, version 2.0

arathunku avatar Jan 09 '22 19:01 arathunku