Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENOTCACHED error from a git dependency when using lock file #134

Open
ento opened this issue Mar 11, 2019 · 12 comments
Open

ENOTCACHED error from a git dependency when using lock file #134

ento opened this issue Mar 11, 2019 · 12 comments

Comments

@ento
Copy link

ento commented Mar 11, 2019

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
js-cookie@2.2.0 /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.

@hlolli
Copy link
Contributor

hlolli commented Mar 18, 2019

I had ENOTCACHED

all I did to fix it was

npm uninstall node2nix -g 

npm i git+https://git@github.com/svanderburg/node2nix.git#c876bb8f8749d53ef759de809ce2aa68a8cce20e --global

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

@jacereda
Copy link
Contributor

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

@jacereda
Copy link
Contributor

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

@jacereda
Copy link
Contributor

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

@ento
Copy link
Author

ento commented Mar 20, 2019

@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.

@jacereda
Copy link
Contributor

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

Ma27 added a commit to Ma27/nixpkgs that referenced this issue Apr 7, 2019
This diff regenerates the package sets for `codimd` and `codemirror`
using NodeJS 8 to get rid of the deprecated[1] `nodejs-6_x`.

Additionally the following issues had to be fixed during the update:

* The package `js-sequence-diagram` has been removed from the NPM
  registry and was replaced by a security holding package[2]. The
  package was published by a third-party (upstream only supports bower
  builds), so it's unclear whether the package will re-appear[3].

  As the tarballs still exist (and the hash didn't change), the package
  will be loaded manually into the build env.

* For the babel-related packages, `dontNpmInstall` will be set for
  `node2nix` installs as some of those packages bundle a
  `package-lock.json` that triggers `ENOTCACHED` errors for optional
  dependencies[4].

For now it should be sufficient to use NodeJS 8 (`codimd` v1.2.x doesn't
support NodeJS 10), in the long term we probably want to use `yarn2nix`
here with NodeJS 10. This is much rather a fix to get rid of another
NodeJS 6 dependency.

[1] `nodejs-6_x` is about to be deprecated, see NixOS#58976
[2] https://www.npmjs.com/package/js-sequence-diagrams,
    https://github.com/npm/security-holder
[3] bramp/js-sequence-diagrams#212
[4] svanderburg/node2nix#134
lheckemann pushed a commit to NixOS/nixpkgs that referenced this issue Apr 7, 2019
This diff regenerates the package sets for `codimd` and `codemirror`
using NodeJS 8 to get rid of the deprecated[1] `nodejs-6_x`.

Additionally the following issues had to be fixed during the update:

* The package `js-sequence-diagram` has been removed from the NPM
  registry and was replaced by a security holding package[2]. The
  package was published by a third-party (upstream only supports bower
  builds), so it's unclear whether the package will re-appear[3].

  As the tarballs still exist (and the hash didn't change), the package
  will be loaded manually into the build env.

* For the babel-related packages, `dontNpmInstall` will be set for
  `node2nix` installs as some of those packages bundle a
  `package-lock.json` that triggers `ENOTCACHED` errors for optional
  dependencies[4].

For now it should be sufficient to use NodeJS 8 (`codimd` v1.2.x doesn't
support NodeJS 10), in the long term we probably want to use `yarn2nix`
here with NodeJS 10. This is much rather a fix to get rid of another
NodeJS 6 dependency.

[1] `nodejs-6_x` is about to be deprecated, see #58976
[2] https://www.npmjs.com/package/js-sequence-diagrams,
    https://github.com/npm/security-holder
[3] bramp/js-sequence-diagrams#212
[4] svanderburg/node2nix#134

(cherry picked from commit 5feec42,
PR #59118)
@oneingan
Copy link

oneingan commented May 2, 2019

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

@svanderburg
Copy link
Owner

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: 5bea6e5

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
Copy link
Owner

node2nix 1.7.0 contains preliminary git sub module support now.

@oneingan
Copy link

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.

@Staff-d
Copy link

Staff-d commented Oct 6, 2021

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.

@arathunku
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants