Welcome to the Netlify Forums and thanks reaching out. There are multiple reasons why a build may be taking a bit of time, so we will need a bit more information in order to look into this.
Can you please share the following:
A full copy of your most recent deploy log
A link to your site
You project repo, if public
If not public, can you please share your package.json file or your .toml file?
Lastly, this is a good resource that covers optimizing your build time:
Weβve also found cache to be slower than a cache-free install with yarn. In some cases using the cache almost doubles our total build time. Our latest comparison resulted in a cache build at 7m 42s, cache-free 4m 13s.
I donβt know that Iβve seen the cache make things faster, and over time gradually slows the build down even more.
My guess as to why this happens is the cache keeps growing in size as modules are upgraded, and the cache keeps the old versions around.
It would be nice if the cache was faster, or there was an option to turn off the cache. Customers would get faster builds, and Netlify wouldnβt be paying the extra price for longer builds/unnecessary storage.
Yeah, recently did a lot of experiments with AWS CodeBuild and also came to the same conclusion. Even at AWS scale, pulling cache from S3, within the same region, extracting it, linking and all of that jazz is slower by a magnitude of x2 than just doing βyarn installβ.
My guess is that pulling many small files in parallel is just somehow faster than pulling one monolith of a cache.
I hear you both, but what you both are experiencing is probably coming from environments that youβre trying to test. Youβve your own code bases, your own set of dependencies, and other stuff, but we also have a lot more users who are having faster builds due to cache. Iβm not saying itβs just the two of you with this issue, no, weβve had such requests in the past, but each site is different and has different requirements. So itβs difficult to target all in one go.
The only possible solution I see to this is to provide an option to users to disable the build cache so that caching is not forced. Is that it or do you have any other suggestions? Also, at the moment, you can use the Netlify API to trigger builds without cache. Would that work for your use cases?
On a side note, I think thereβs a possible workaround for you all till then. You can configure the build command to delete your node_modules, your repo, and other directories after your build command. If these directories wonβt exist, they wonβt end up in cache.
I donβt think our environment is that special. Its a typical create-react-app, typescript, jest, storybook, MUI project with some additional modules. Granted all the dependencies do come in kind of heavy. Our cache is also around 800MB - 900MB like @moltar.
Having an option to disable cache in config would be helpful on our end.
Iβm not sure weβll go the API route just yet. If we go down that path weβd probably invest in building outside of netlify too.
When I said you need to clear node_modules, I didnβt mean to ask you to do it during the build command. I should have specified better. So you could create a build plugin, and use something like cache utils: Create Build Plugins | Netlify Docs, to delete the cache.