yarnpnp2nix
yarnpnp2nix copied to clipboard
Executing yarn scripts as part of `build` fails
When using yarn
inside a build script, e.g.
"testb@workspace:packages/testb" = {
build = ''
yarn build # defined in package.json as `node build.js`
'';
};
The following error occurs:
Internal Error: testb@workspace:.: This package doesn't seem to be present in your lockfile; run "yarn install" to update the lockfile
I have already tried copying ./yarn.lock
to the build environment, i.e.
build = ''
cp ${workspace/yarn.lock} ../../yarn.lock
yarn build
'';
but this doesn't seem to change anything
Yes this is unsupported for now, but you can run node build.js
or whatever your build script is. Any CLI bins provided by dependencies or dev dependencies will be available in the PATH too, so you can run e.g tsc
or esbuild
Thanks for the information, I am trying to get https://github.com/prisma/prisma/ to work inside yarnpnp2nix. To be precise, prisma generate
requires special handling and only works with yarn pnpify
. I have tried to work around this by directly adding --require @yarnpkg/pnpify
but unfortunately it looks like this also depends on the same behavior. The error message looks a bit different (Assertion failed: Expected the package to have been registered
), but it seems to also result from the missing lockfile.
I have solved this differently now, I'm generating the prisma client in a separate derivation without yarn / yarnpnp2nix:
prisma-client = pkgs.stdenv.mkDerivation {
name = "prisma-client";
buildInputs = with pkgs; [ nodejs nodePackages.prisma ];
src = pkgs.nix-filter {
root = packages/prisma;
include = [
packages/prisma/prisma/schema.prisma
];
};
buildPhase = with pkgs; ''
npm install --cache .npm-cache @prisma/client
prisma generate
'';
installPhase = ''
mv generated $out
'';
};
and in the package importing the generated prisma client, I am symlinking the result to the expected location (build.cjs
bundles it, otherwise I suppose a copy would be more appropriate):
yarnPackages = pkgs.mkYarnPackagesFromManifest {
yarnManifest = import ./yarn-manifest.nix;
packageOverrides = {
"@alugha/prisma@workspace:packages/prisma" = {
build = with pkgs; ''
ln -s ${prisma-client} generated
node build.cjs
'';
};
};
};