Open marcofugaro opened 3 years ago
Thanks for raising this @marcofugaro. This is definitely related with #612 and #319 and our usage of the --cache-folder
property 👍 however it isn't particular to your workspace
settings I believe, just the yarn version used.
This issue is five months old today and there is still no solution for Yarn 3 in the public. I tried finding a workaround today but gave up: https://github.com/netlify/build/issues/1535#issuecomment-1021720396 HALP! 🙏
UPD: Workaround: https://github.com/netlify/build/issues/1535#issuecomment-1022988981
Hi, manage to create a workaround for yarn3 using a custom plugin, till #612
First in netlify.toml
use NPM_FLAGS
hack to disable default npm install, here we cannot use NETLIFY_USE_YARN
becase of #779
[build.environment]
NODE_VERSION = "16"
NPM_FLAGS = "--version"
[[plugins]]
package = "/.netlify/netlify-plugin-yarn"
then create .netlify/netlify-plugin-yarn
folder with files
manifest.yml is just
name: netlify-plugin-yarn
inputs: []
and index.js is responsible for moving cache folder, setting YARN_CACHE_FOLDER
and enabling corepack for packageManager in package.json
module.exports = {
onPreBuild: async ({ utils: { build, run } }) => {
const cacheDir = '.yarn_cache'
process.env['YARN_CACHE_FOLDER'] = `${process.env.HOME}/${cacheDir}`
process.env['NETLIFY_CACHE_DIR'] = `${process.env.NETLIFY_BUILD_BASE}/cache`
try {
await run.command(`mv ${process.env.NETLIFY_CACHE_DIR}/${cacheDir} ${process.env.YARN_CACHE_FOLDER}`)
} catch (error) {
console.log('No yarn cache found')
}
try {
await run.command('corepack enable')
} catch (error) {
return build.failBuild(error)
}
},
}
package.json
{
"private": true,
"engines": {
"node": "16.x",
"yarn": "3.2.1"
},
"packageManager": "yarn@3.2.1"
}
Edited ---
Extracted this code into package, https://github.com/piecyk/yarn-berry-netlify-plugin
Related: #612 #432 #319
We are using yarn workspaces with yarn's latest version (
3.0.1
) and yarn is not cached at all, it takes1m 54s
in best cases and3m 17s
in worst cases, including the cache restore phase.On the contrary, on GitHub actions with the yarn cache action, the Fetch phase is completely skipped, and it just runs the linking phase. It takes ~20 seconds.
I pasted the logs at the end of the issue, the relevant part are these:
And there is this warning from yarn, it may be relevant:
Full Netlify build logs (excluding build phase)
``` 4:18:09 PM: Build ready to start 4:18:11 PM: build-image version: c6001ed68662a13e5deb24abec2b46058c58248a 4:18:11 PM: build-image tag: v3.9.0 4:18:11 PM: buildbot version: d2795bf5a96b85e585e90944f15f15381ce164a7 4:18:11 PM: Fetching cached dependencies 4:18:11 PM: Starting to download cache of 802.8MB 4:18:15 PM: Finished downloading cache in 3.951667197s 4:18:15 PM: Starting to extract cache 4:18:31 PM: Finished extracting cache in 16.395963806s 4:18:32 PM: Finished fetching cache in 20.470693303s 4:18:32 PM: Starting to prepare the repo for build 4:18:32 PM: Preparing Git Reference pull/1028/head 4:18:35 PM: Parsing package.json dependencies 4:18:35 PM: Starting build script 4:18:35 PM: Installing dependencies 4:18:35 PM: Python version set to 2.7 4:18:36 PM: Started restoring cached node version 4:18:38 PM: Finished restoring cached node version 4:18:39 PM: v16.7.0 is already installed. 4:18:40 PM: Now using node v16.7.0 (npm v7.20.3) 4:18:40 PM: Started restoring cached build plugins 4:18:40 PM: Finished restoring cached build plugins 4:18:40 PM: Attempting ruby version 2.7.1, read from environment 4:18:40 PM: Started restoring cached ruby version 4:18:40 PM: Finished restoring cached ruby version 4:18:42 PM: Using ruby version 2.7.1 4:18:42 PM: Using PHP version 5.6 4:18:42 PM: Started restoring cached yarn cache 4:18:42 PM: Finished restoring cached yarn cache 4:18:44 PM: Found yarn version (3.0.1) that doesn't match expected (1.22.4) 4:18:44 PM: up to date, audited 1 package in 261ms 4:18:44 PM: found 0 vulnerabilities 4:18:44 PM: Installing yarn at version 1.22.4 4:18:44 PM: Installing Yarn! 4:18:44 PM: > Downloading tarball... 4:18:44 PM: [1/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz --> /tmp/yarn.tar.gz.uavJVbtnLD 4:18:44 PM: % Total % Received % Xferd Average Speed Time Time Time Current 4:18:44 PM: Dload Upload Total Spent Left Speed 4:18:45 PM: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 4:18:45 PM: 100 79 100 79 0 0 351 0 --:--:-- --:--:-- --:--:-- 352 4:18:45 PM: 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 4:18:45 PM: 100 93 100 93 0 0 146 0 --:--:-- --:--:-- --:--:-- 451 4:18:45 PM: 100 625 100 625 0 0 684 0 --:--:-- --:--:-- --:--:-- 684 4:18:46 PM: 100 1215k 100 1215k 0 0 1006k 0 0:00:01 0:00:01 --:--:-- 1006k 4:18:46 PM: [2/2]: https://yarnpkg.com/downloads/1.22.4/yarn-v1.22.4.tar.gz.asc --> /tmp/yarn.tar.gz.uavJVbtnLD.asc 4:18:46 PM: 100 83 100 83 0 0 1853 0 --:--:-- --:--:-- --:--:-- 1853 4:18:46 PM: 100 97 100 97 0 0 1318 0 --:--:-- --:--:-- --:--:-- 1318 4:18:46 PM: 100 629 100 629 0 0 6041 0 --:--:-- --:--:-- --:--:-- 6041 4:18:46 PM: 100 1028 100 1028 0 0 8914 0 --:--:-- --:--:-- --:--:-- 8914 4:18:46 PM: > Verifying integrity... 4:18:46 PM: gpg: Signature made Mon 09 Mar 2020 03:52:13 PM UTC using RSA key ID 69475BAA 4:18:46 PM: gpg: Good signature from "Yarn Packaging