Cloudflare is rebuilding node_modules in every build

Cloudflare isn't caching the node_modules folder so that consequents build run faster. I see the message Started restoring cached node modules and Finished restoring cached node modules messages on the top of all the deployment logs. But it's not working actually. npm used to reinstall and download all the dependencies every time. Now, I am using pnpm, and the pnpm store is set to node_modules/.pnpm-store but it's redownloading and installing all the dependencies every time. I am also using astro-imagetools which stores its cache inside node_modules/.cache/astro-imagetools which is also not working. And it's heavily impacting the build time. I have tested both retrying deployments, adding a new commit, and triggering the deploy hooks. But none of them is able to restore the node_modules.
9 Replies
Hello, I’m Allie!
No idea why it is logging that, but the current implementation doesn't share any state between builds, so it shouldn't be able to cache dependencies at all
Muhymin
MuhyminOP2y ago
Oo... Is it on the roadmap?? Or @HardAtWork, is there any directory (maybe a system directory) that is persistent and accessibel too??
Hello, I’m Allie!
There is not. You can do it manually by syncing with an external storage system, but when a build is completed, everything is wiped Or use GH Actions
Muhymin
MuhyminOP2y ago
GH Actions to do what??
Hello, I’m Allie!
Build your project in GH Actions(which should be able to cache dependencies), and then deploy to Pages. Instead of using Pages CI
Muhymin
MuhyminOP2y ago
Yeah, I got that but it is possible to deploy to Pages programmatically?! I didn't know that
Muhymin
MuhyminOP2y ago
Thanks! HI 👋 @HardAtWork ! If I build the website using GitHub actons and then deploy the built directory to Cloudflare, then what's the best way to rebuild the website on CMS update??
Want results from more Discord servers?
Add your server