Skip `yarn install` when using yarn 2 with zero install

Is there a way to fully skip the yarn install step? I found this ticket about prebuild config, but it seems to have stalled out a bit. :upside_down_face:

Yarn 2 offers a zero-install option which I’d like to try out on a project. Unfortunately, it seems like using it at present greatly increases build times as the Netlify CI is not properly reading out of the .yarn/cache directly. Really, I’d like to just run my build step without running install at all… is there a way to achieve this at present?

1 Like

Sure - don’t have a yarn.lock in the root of your repo, (or your base directory if you use one). Otherwise we will ALWAYS run yarn install for you. You could try monkeying with the $YARN_FLAGS variable so we run e.g. yarn install --dry-run (not sure if that is the real dry run parameter, but you get the idea :))

Hm. I definitely will still need the yarn.lock and package.json files committed in my repo. Is there an easy way to remove it before Netlify bots check the site?

--dry-run also isn’t an available flag in Yarn 2. Ideally, I’d like to save the install time and running something like yarn --immutable still reruns some commands.

Trolling through the run_yarn conditions it looks like this isn’t going to be possible at present…

There is an open PR for adding a prebuild steps hook. This might at least partially address the issue. However, I think the most direct solution would to be a flag for zero installs. In my case, the package.json file will still be needed as I will run build commands through yarn. However, since I’ve committed all of the necessary packages in .yarn/cache I don’t need anything installed.

For the preinstall suggestion to work I’d have to the rename the file again before building. At any rate, it looks like it isn’t an option at present. So I’ll just keep an eye out for support of this feature.

2 Likes

thanks for documenting your process here as you investigate, @kara-todd. I’ll look and see if we want to file a feature request for this. If we do, we’ll link it here and report back once we know more.

1 Like