When you use yarn inside of a nix-shell, you need to pin it to the associated nodejs version you’re planning on using, otherwise it uses the default of the nix pkgs.

Here’s an article that I used to find a good example of it.

my shell.nix for using nodejs-16_x ended up being:

{ pkgs ? import <nixpkgs> {} }:
with pkgs;
  nodejs = pkgs.nodejs-16_x;
  yarn = pkgs.yarn.override { inherit nodejs; };
in pkgs.mkShell {
  buildInputs = [
  # for specifying which version to use if need be
  shellHook = ''
    yarn set version 3.x