Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Pipelines: cache custom node_modules folder

Do I understand correctly that pre-defined `node` cache only works when node_modules and package.json are located in the root directory of a project? Then how do I configure bitbucket-pipelines.yml to make cache work with node_modules folder located in subfolder (./public/node_modules/)? 

1 answer

1 accepted

6 votes
Answer accepted

Managed to solve it



- step
- node-custom
- if [ ! -d "node_modules" ]; then npm install; fi

node-custom: public/node_modules

Will that not cause problems if package.json is updated as the node_modules won't be re-generated once cached?

It will. You need to manually delete your cached dependencies using the UI.

There sure must be a way how to delete it automatically when package-lock.json changes?

@Petr Pelleractually, you don't need that line:

- if [ ! -d "node_modules" ]; then npm install; fi

Because the npm knows when to install/remove packages, I just changed this line by simply:

- npm install

And it works fine for me.

Like Roman likes this

I got on this problem while trying to set up a monorepo. And even more - i want to spare the execution of costly npm command. So I generated MD5 hash of the package-lock.json and then cache node_modules AND the MD5 hash. So far looks to be working fine. 

app1: app1/node_modules
app1-cache-key: app1/package-lock.md5

- step:
- cd app1
- package-lock.md5
- if [[ $(cat package-lock.md5 || '') != $(md5 package-lock.json) ]]; then npm ci && echo "$(md5 package-lock.json)" > package-lock.md5 ; fi

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,158 views 2 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you