Question

Caching node_modules with yarn workspaces

I’m having issues with my monorepo deployment using app platform. I’m using yarn workspaces to manage dependencies. When running a new deploy and using the node_modules cache, the build fails with missing modules.

My monorepo folder structure is basically like this:

apps/
  server/
  web/
packages/
  common/
yarn.lock

I’m using turborepo to manage the build pipeline, so I use the root directory as source_dir. Each app runs as a service in my app, with build command like this yarn build --scope="<app>" --include-dependencies, which builds local dependencies before building the app.

Whenever the cache layer is restored, the following build fails with missing node_modules. I can work around this issue by simply forcing a redeploy without cache, but it is kind of tedious.

I wonder if there is some general caching issue with yarn workspaces? Haven’t been able to find anything in documentation suggesting another configuration. Could work on a reproducible repo if there is no immediate suspicion.

Show comments

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I am experiencing the same issue

I share a similar setup and facing the exact same problem.

Here is a snippet from the log.

Detected the following buildpacks suitable to build your app:
[2022-11-17 16:14:03] │ 
[2022-11-17 16:14:03] │    heroku/nodejs-engine   v0.5.1  
[2022-11-17 16:14:03] │    digitalocean/node      v0.3.4  (Node.js)
[2022-11-17 16:14:03] │    digitalocean/procfile  v0.0.3  (Procfile)
[2022-11-17 16:14:03] │    digitalocean/custom    v0.1.1  (Custom Build Command)
[2022-11-17 16:14:03] │ 
[2022-11-17 16:14:03] │ For documentation on the buildpacks used to build your app, please see:
[2022-11-17 16:14:03] │ 
[2022-11-17 16:14:03] │    Node.js  v0.3.4  https://do.co/apps-buildpack-node
[2022-11-17 16:14:03] ╰─────────────────────────────────────────────╼
[2022-11-17 16:14:03] 
[2022-11-17 16:14:03] ╭──────────── build caching ───────────╼
[2022-11-17 16:14:03] │  › checking for cache from a previous build
[2022-11-17 16:14:05] │ Restoring metadata for "heroku/nodejs-engine:nodejs" from app image
[2022-11-17 16:14:05] │ Restoring metadata for "heroku/nodejs-engine:yarn" from app image
[2022-11-17 16:14:05] │ Restoring metadata for "heroku/nodejs-engine:toolbox" from cache
[2022-11-17 16:14:05] │ Restoring metadata for "digitalocean/node:node_modules" from cache
[2022-11-17 16:14:06] │ Restoring data for "heroku/nodejs-engine:nodejs" from cache
[2022-11-17 16:14:06] │ Restoring data for "heroku/nodejs-engine:toolbox" from cache
[2022-11-17 16:14:06] │ Restoring data for "heroku/nodejs-engine:yarn" from cache
[2022-11-17 16:14:06] │ Restoring data for "digitalocean/node:node_modules" from cache
[2022-11-17 16:14:16] ╰───────────────────────────────────────╼
[2022-11-17 16:14:16] 
[2022-11-17 16:14:16] ╭──────────── app build ───────────╼
[2022-11-17 16:14:16] │ ---> Node.js Buildpack
[2022-11-17 16:14:16] │ ---> Installing toolbox
[2022-11-17 16:14:16] │ ---> Getting Node version
[2022-11-17 16:14:16] │ ---> Resolving Node version
[2022-11-17 16:14:17] │ ---> Reusing Node v16.16.0
[2022-11-17 16:14:17] │ ---> Parsing package.json
[2022-11-17 16:14:18] │ ---> Installing yarn@1.22.19
[2022-11-17 16:14:20] │ ---> No file to start server
[2022-11-17 16:14:20] │ ---> either use 'docker run' to start container or add index.js or server.js
[2022-11-17 16:14:20] │ Project contains yarn.lock, using yarn
[2022-11-17 16:14:20] │ Reusing cached node_modules from yarn.lock
[2022-11-17 16:14:23] │ Running custom build command: yarn build --filter=api
[2022-11-17 16:14:24] │ yarn run v1.22.19
[2022-11-17 16:14:24] │ $ turbo build --filter=api
[2022-11-17 16:14:24] │ • Packages in scope: api
[2022-11-17 16:14:24] │ • Running build in 1 packages
[2022-11-17 16:14:24] │ • Remote caching disabled
[2022-11-17 16:14:24] │ api:build: cache miss, executing ac8bc1e9485e9786
[2022-11-17 16:14:25] │ api:build: $ rimraf dist
[2022-11-17 16:14:25] │ api:build: $ nest build
[2022-11-17 16:14:29] │ api:build: src/activities/activities.controller.ts:11:8 - error TS2307: Cannot find module '@nestjs/common' or its corresponding type declarations.
[2022-11-17 16:14:29] │ api:build: 
[2022-11-17 16:14:29] │ api:build: 11 } from '@nestjs/common';
[2022-11-17 16:14:29] │ api:build:           ~~~~~~~~~~~~~~~~
[2022-11-17 16:14:29] │ api:build:  

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up