mkYarnPackage: Lockfile has incorrect entry

I’m trying to package marp-cli with yarn2nix: GitHub - marp-team/marp-cli: A CLI interface for Marp and Marpit based converters

However build complains with

error: builder for '/nix/store/9af4bw297961rx7wc8a2yyzap2fqn0wh-marp-team-marp-cli-modules-2.1.4.drv' failed with exit code 1;
       last 10 log lines:
       > warning Lockfile has incorrect entry for "pug-runtime@^2.0.4". Ignoring it.
       > error Couldn't find any versions for "pug" that matches "^2.0.3" in our cache (possible versions are ""). This is usually caused by a missing entry in the lockfile, running Yarn without the --offline flag may help fix this issue.
       > info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
       > Error: Couldn't find any versions for "pug-runtime" that matches "^2.0.4" in our cache (possible versions are ""). This is usually caused by a missing entry in the lockfile, running Yarn without the --offline flag may help fix this issue.
       >     at MessageError.ExtendableBuiltin (/nix/store/8lajm4glg9v9f7lzpz4r4gm02rqwgnkl-yarn-1.22.18/libexec/yarn/lib/cli.js:721:66)
       >     at new MessageError (/nix/store/8lajm4glg9v9f7lzpz4r4gm02rqwgnkl-yarn-1.22.18/libexec/yarn/lib/cli.js:750:123)
       >     at NpmResolver.<anonymous> (/nix/store/8lajm4glg9v9f7lzpz4r4gm02rqwgnkl-yarn-1.22.18/libexec/yarn/lib/cli.js:50430:15)
       >     at Generator.next (<anonymous>)
       >     at step (/nix/store/8lajm4glg9v9f7lzpz4r4gm02rqwgnkl-yarn-1.22.18/libexec/yarn/lib/cli.js:310:30)
       >     at /nix/store/8lajm4glg9v9f7lzpz4r4gm02rqwgnkl-yarn-1.22.18/libexec/yarn/lib/cli.js:321:13
       For full logs, run 'nix log /nix/store/9af4bw297961rx7wc8a2yyzap2fqn0wh-marp-team-marp-cli-modules-2.1.4.drv'.
error: 1 dependencies of derivation '/nix/store/9lxxd3250h492b4s2lvxcf53ral42mcn-marp-cli.drv' failed to build

I’ll be honest, I’m a bit dumbfounded, any pointer would be appreciated.

My minimal flake to reproduce:

{
  nixConfig.bash-prompt-prefix = "(nix) ";

  inputs.flake-utils = {
    url = "github:numtide/flake-utils";
    inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { nixpkgs, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let pkgs = nixpkgs.legacyPackages.${system};
      in
      {
        packages.default = pkgs.mkYarnPackage {
          name = "marp-cli";
          version = "2.1.4";
          src = pkgs.fetchFromGitHub {
            owner = "marp-team";
            repo = "marp-cli";
            rev = "v2.1.4";
            sha256 = "TkjaCiKrorYF8Ml8Xps3xZxcN5ePTpv2Jw1c2Icqtm8=";
          };
        };
      }
    );
}

I have a similar issue when trying to package the front-end of TandoorRecipes.

       > success Set "yarn-offline-mirror" to "/nix/store/jv24lbh5iw4ryyg9maybb1rxlv2pmmac-offline".
       > Done in 0.07s.
       > yarn install v1.22.19
       > [1/4] Resolving packages...
       > warning Lockfile has incorrect entry for "workbox-webpack-plugin@^6.1.0". Ignoring it.
       > error Couldn't find any versions for "workbox-webpack-plugin" that matches "^6.1.0" in our cache (possible versions are ""). This is usually caused by a missing entry in the lockfile, running Yarn without the --offline flag may help fix this issue.
       > info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

I’m not familiar enough with the JS ecosystem to really understand why the lockfile is invalid, after a cursory glance it looks fine to me.

Don’t use mkYarnPackage.

{ lib, stdenv, fixup_yarn_lock, callPackage, yarn, nodejs-slim }:

stdenv.mkDerivation {
  pname = "foo";
  version = "1.0.0";

  src = lib.cleanSource ./.;

  yarnOfflineCache = (callPackage ./yarn.nix {}).offline_cache;
  # or fetchYarnDeps

  nativeBuildInputs = [
    fixup_yarn_lock yarn nodejs-slim
  ];

  configurePhase = ''
    export HOME=$NIX_BUILD_TOP
    yarn config --offline set yarn-offline-mirror $yarnOfflineCache
    fixup_yarn_lock yarn.lock
    yarn install --offline --frozen-lockfile --ignore-scripts --no-progress --non-interactive
    patchShebangs node_modules/
  '';

  buildPhase = ''
    ...
  '';

  installPhase = ''
    ...
    # if the node_modules dir is needed at runtime, move it to $out/libexec here
  '';
}

If you do use mkYarnPackage, you have to set the packageResolutions parameter to the contents of the resolutions field in the package.json.

2 Likes

Aaah, did not know about packageResolutions.

Is there a way to automatically take care of that, through an update script or some fromJSON nixery?

EDIT: seems like having packageResolutions = (lib.importJSON ./tandoor-recipes-package.json).resolutions; is not enough. And I can’t find any documentation about this field :upside_down_face:.

yeah, I am hitting this with olaris-react in fetchYarnDeps: couldn't find any versions but yarn install works · Issue #203708 · NixOS/nixpkgs · GitHub and your flx @yureka, did not improve anything

See mkYarnPackage: fix uncopied resolutions field by GuillaumeDesforges · Pull Request #214952 · NixOS/nixpkgs · GitHub

1 Like