'Caching node_modules between builds

According to the docs and other questions here it’s been raised that caching node_modules is a no-go given the structure of the node_modules can break between node versions requiring a re-install. See https://docs.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#nodejsnpm

My question: is there any downside to caching node_modules IF I were to make a part of the cache key the current node version + agent os? Given I am building using the LTS Ubuntu and I have pinned it to specifically ubuntu-20.04 would this be safe? Or do I need to continue caching only the cache folder?

Cheers



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source