Is it normal to have to install dependencies again on every build?

Hello, my netlify site name is coccamp-web.netlify.app
I built it from the starter with Sanity and Eleventy. The package came with lerna to manage the two separate folders. The way I set it up now, the builds to the eleventy site should be triggered only from the cms. As it is already deployed and working, I decided to remove the ‘lerna bootstrap’ command before the eleventy build, because as I see this elevates the build time, and the only thing that I really need is that Eleventy run its querys again to get the fresh content from Sanity.
But when I removed the ‘lerna bootstrap’ command, I receive in the build log "Error: Cannot find module ‘@sanity/block-content-to-html’’ as if the dependency is not installed? The first time it happened, I placed the lerna command back to see if maybe something was uninstalled by accident, but no - this happens everytime. With the bootstrap command the build passes, without it it says the dependency is not found. Why would that be?

the command that passes: lerna bootstrap && npm run build-web
command that fails: npm run build-web

Thanks for any responses

One of the things Lerna does is connect multiple dependencies together, something npm doesn’t handle for you. Is it possible you have multiple package.json files and are defining dependencies in two different locations?

For instance

package.json
subfolder/package.json
anotherfolder/withafolder/package.json

Sorting this kind of issue is the core feature of Lerna.

yes, that’s exactly. it’s a monorepo with the studio and the web interface so I got:

./web/package.json
./studio/package.json

but the point is I don’t want to reinstall dependencies anymore, after the site is already online. I would like to just run the eleventy command. on localhost this works. do you know if netlify doesn’t keep dependencies installed?

Dependencies are something you just need during the build process, you don’t need to keep them permanently “installed”. Netlify caches the dependencies (Or perhaps just some?) to speed up the build process, but you cannot rely on them always being there.

Netlify replaces everything you build every time you build, in other words, you can’t build the “full website” one time, and then subsequently just build small portions of your website later; Netlify will always build the entire website and replace the old website with the “new one”, even if you just changed a small portion of it.

There is no way for Netlify to know what you’re intending to do when you switch build commands, from a resource perspective, then it doesn’t make sense for Netlify to have all your dependencies installed 24/7 like you do on your dev machine.

1 Like

Yes dependencies are cached.

After the initial build, we’ll cache the dependencies so we don’t have to install them every time you push an update.

as mentioned in the Manage dependencies section of the docs.

There are also monorepo-specific build configurations.

Netlify does rebuild your site each time, but only new files are sent to the CDN.

1 Like

When he changes the build command he’s also changing his dependencies, the cache would naturally update accordingly.

1 Like

Thanks guys for both of the answers! It really clarified some things to me. So, indeed Netlify is keeping the cache of my dependencies, I now noticed in the beginning of the log:

Fetching cached dependencies
Starting to download cache of 107.5MB

I’m still not entirelly sure why the config I made now is not returning error of dependencies missing, but it’s working, and I replaced lerna with the regular eleventy buid command. My build time dropped from 1 minute to 15 seconds! That’s great!
I am pretty sure there was something to do with the cache, and how it changes when we modify the command, as it’s mentioned in the docs @coelmay linked.

1 Like