buildNpmPackage - ENOTCACHED very late into build

I’m trying to package Fantasia Archive from source(bc it sounds like a better idea than wrapping an AppImage) and I’m getting an ENOTCACHED error after the compiling finished (i think).
Anyway here’s my nix file

with import <nixpkgs> {};

buildNpmPackage rec {
    pname = "fantasia-archive";
    version = "0.1.14";

    src = fetchFromGitHub {
        owner = "Elvanos";
        repo = "fantasia-archive-v1";
        rev = "v${version}";
        hash = "sha256-D4haoMAAIY5+QCVuR0hlAYDTzC1PsyEzEyZw4uprxtg=";
    };

    nativeBuildInputs = [ nodePackages.node-gyp-build electron ];

    npmDepsHash = "sha256-tFGg8WD7aR3sOkOB8sAJ8x1KfJqW4JwqfZQ/B2OKk8g=";
    
    env = {
      ELECTRON_SKIP_BINARY_DOWNLOAD = 1;
    };

    npmPackFlags = [ "--ignore-scripts" ];

    NODE_OPTIONS = "--openssl-legacy-provider";

    meta = {
      description = "An offline database manager for world building";
      homepage = "https://fantasiaarchive.com/";
      license = lib.licenses.gpl3;
    };
}

And that’s the log (only a part bc the entire thing is rly long and i’m unsure it’s necessary)



 App · ⚠️  Build succeeded, but with 131 warnings. Check log above.

 Main process summary for css/js/json (the rest are omitted):
 ╔══════════════════╤══════════╤═════════╗
 ║            Asset │     Size │ Gzipped ║
 ╟──────────────────┼──────────┼─────────╢
 ║ electron-main.js │ 14.97 KB │ 5.59 KB ║
 ╟──────────────────┼──────────┼─────────╢
 ║     package.json │  1.00 KB │ 0.57 KB ║
 ╚══════════════════╧══════════╧═════════╝
 
 App · Running "npm install --production"

npm warn config production Use `--omit=dev` instead.
npm error code ENOTCACHED
npm error request to https://registry.npmjs.org/@types%2ffs-extra failed: cache mode is 'only-if-cached' but no cached response is available.
npm error Log files were not written due to an error writing to the directory: /nix/store/bkn0sllgp141zbgfpdfsaq9p0g231y5m-fantasia-archive-0.1.14-npm-deps/_logs
npm error You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

 App · Command "npm" failed with exit code: 1
 App · ⚠️  [FAIL] npm failed installing dependencies

ERROR: `npm build` failed

Here are a few things you can try, depending on the error:
1. Make sure your build script (build) exists
  If there is none, set `dontNpmBuild = true`.
2. If the error being thrown is something similar to "error:0308010C:digital envelope routines::unsupported", add `NODE_OPTIONS = "--openssl-legacy-provider"` to your derivation
  See https://github.com/webpack/webpack/issues/14532 for more information.

The things i tried:

  • npm update the package-lock.json and add a patch to swap it to the new one (exactly the same error)

  • setting dontNpmInstall to true, also doesn’t seem to change anything

I don’t have any experience with npm, so i’m probably not the best person to be doing this, but nobody else is even working on it(accept for one draft pr that hasn’t been updated for over a year). Any help is appreciated

1 Like

It could be a broken lockfile (that you have to delete, regenerate, and use) - I know you mentioned you tried regenerating, but not sure if you deleted the existing one first. Or it might be a case of needing to add

  npmFlags = [ "--legacy-peer-deps" ];

At least that’s usually what I tried with npm errors :stuck_out_tongue:

It seems your App tries to run
‘npm install’

You should see if there is an alternative run command or if you can patch that because it seems to try to download stuff which is OFC not possible in the build sandbox.

Alternatively you could also vendor the lockfile. Just check what npm trying to download and add it to the lockfile yourself in advance

That would be it. Quasar (which is used to build this) runs npm install and after some searching adding a --skip-pkg resolves the issue.