Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executing yarn scripts as part of build fails #7

Open
niklaskorz opened this issue Mar 16, 2023 · 4 comments
Open

Executing yarn scripts as part of build fails #7

niklaskorz opened this issue Mar 16, 2023 · 4 comments

Comments

@niklaskorz
Copy link

niklaskorz commented Mar 16, 2023

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
@niklaskorz
Copy link
Author

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

@madjam002
Copy link
Owner

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

@niklaskorz
Copy link
Author

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.

@niklaskorz
Copy link
Author

niklaskorz commented Mar 17, 2023

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
      '';
    };
  };
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants