Node not found

I’m a NixOS noob, still feeling my way. I’ve been writing NextJS and Svelte apps, and figured out today how to get Jupyter/Python/Pandas working, but now am running into a problem with a simple node script. It is failing at const { createCanvas } = require("canvas");. The error is Error: cannot open shared object file: No such file or directory. I have libuuid installed, as well as nodejs. I am not using flakes nor home manager.

I’m a little confused about how node package dependencies are handled in NixOS perhaps. So far, Svelte and NextJS apps have acted as usual, creating the package.json and node_modules directories as normal. Now I’m doing a NodeJS script and don’t quite understand the behavior. (p)npm install does not create a package.json or lockfile or anything like that, nor does it create a node_modules directory. I assume this is normal from what I read on the Wiki. I don’t quite understand how this works, but pnpm says everything is up to date.

But I am getting the above error. Is this a PATH issue? I’m at a loss here.
I did use a flake for the first time to set up jupyter so if that’s a solution to this problem I’d be happy with that.

Edit: It was a PATH issue. I found the library and prepended LD_LIBRARY_PATH=/nix/store/…, which got me to the next error:

Error: The module '/home/biscotty/node_modules/.pnpm/canvas@2.11.2/node_modules/canvas/build/Release/canvas.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 120. This version of Node.js requires
NODE_MODULE_VERSION 108. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).

I thought these were provided by nodePackages.pnpm (I had been using nodPackages_latest.pnpm, but tried it with the plain .pnpm with no different result.) I tried pnpm rebuild which seemed to do something, but I ended up with the same error. If I understand correctly. Trying with just npm fails with 11508 error Cannot read properties of null (reading 'matches')

My configuration.nix includes

1 Like

Did you find a solution? My deleting the node_modules/ folder and reinstalling dependencies will help?

I had exactly the same problem today. I solved it by wrapping the binaries in my home-manager configuration. It’s probably not the best way to do it and I would appreciate feedback.

{ pkgs, lib, ... }:

  nodejs = pkgs.nodejs_20;
  # Adding libuuid to some node binaries are required by the
  # "node-canvas" package
  wrapWithMissingLibraries =
    pkgs.writeShellScriptBin (baseNameOf binaryFile) ''
      LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath [ pkgs.libuuid ]}";
      export LD_LIBRARY_PATH
      exec ${binaryFile} "$@";
  node = wrapWithMissingLibraries (lib.getExe nodejs);
  yarn = wrapWithMissingLibraries (lib.getExe pkgs.yarn);
  home.packages = [

Thanks a lot.

I have switched to using flakes and it is working well so far, although I haven’t fully tested it since I’ve been very R focused lately. But I’ve noted this and will try it my flake approach flakes out on me :slight_smile:

Edit: just realized I haven’t actually gotten back to JS yet…I was thinking of Python which I got working. When I get time I’ll return to JS. Thanks again.