How to deal with NPM peerDependencies?

I submitted this package to nixpkgs but I still have issues using it.

When I use it with treefmt-nix I get this error:

prettier error:
[error] Cannot find module 'prettier'
[error] Require stack:
[error] - /nix/store/kfqky7m9az531rkar5kfs5jzird0slyv-prettier-plugin-go-template-0-unstable-2023-07-26/lib/node_modules/prettier-plugin-go-template/lib/index.js

prettier is included in package.json as peerDependencies but does not get build.

What’s the best way of dealing with this?

I believe floco handles peerDependencies correctly.

Shouldn’t they be handled by buildNpmPackage too?

I’m not certain of that. I think it’s the contents of the lockfile that end up being present. Is it in the lockfile?

It’s there as a peerDependency, but is it there as a locked node in the resolved tree?

How do I check that?

Does it show up again in the lockfile?

Well, then it seems that it should be picked up by the Nix tooling and made available. But I’m no expert. If it’s anything similar to how Python dependencies are implemented, then your executable should be a script that defines some variables and runs Node.js. You may be able to inspect the values for those variables and see whether prettier is present.

@winter Does buildNpmPackage not handle peerDependencies?

We do handle those in npmlock2nix.

As you previously pointed out, the peer dependencies are available in the lockfile. They’re a way to point a hard dependency between a host package and a precise version. More infos there: Node.js — Peer Dependencies

I’m not familiar with buildNpmPackage, but I can describe how we handle those in npmlock2nix: we plain remove them from the lockfile (test here). They should have been already set in stone by the npm resolver during the lockfile generation.