Cache optimization using pnpm, next and nx
Unanswered
Giant panda posted this in #help-forum
Giant pandaOP
I'm using a monorepo solution called nx to manage several next apps. I also use github actions to run my CIs and I'm struggling to cache properly my builds.
Here's the relevant workflow steps:
But I keep running into warning messages in builds about no caches and stuff.
EDIT:
Here's the warning message:
Does anyone have any experience in that?
Thanks!
Here's the relevant workflow steps:
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v3
name: Setup pnpm & next caches
with:
path: |
${{ env.STORE_PATH }}
${{ github.workspace }}/dist/
# Generate a new cache whenever packages or source files change or prisma model changes.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**/*.[jt]s', '**/*.[jt]sx', '**/*.prisma') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
But I keep running into warning messages in builds about no caches and stuff.
EDIT:
Here's the warning message:
warn No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
Does anyone have any experience in that?
Thanks!
23 Replies
can you share the exact warning message?
and your full action file if possible
and btw, cache can't be overwritten, so you should add
github.workspace
to your cache keythat error is because your not caching the
.next/cache
folder (made by nextjs)Giant pandaOP
Thanks for your answers.
The
The
dist/
directory consists of nextjs apps that each contain the .next directory. Should I explicitly list them?so what is
github.workspace
in this contextand you should be not caching things that are in the code themself - waistful
Giant pandaOP
it's the root of the nx monorepo project
and then where is your building of nextjs
Giant pandaOP
I don't know if you're familiar with nx, but basically nx builds and outputs all the apps builds into the
dist/
directoryas it would make the most sense to use matrix to build them all and create individual cache for each
Giant pandaOP
and more specifically under
dist/apps/app-a/...
yeah i don't fully know it
Giant pandaOP
No worries 🙂
so, it copies your code to dist?
Giant pandaOP
it outputs the built code to dist under a specific folder, relevant to the app yeah
as most systems would do
apps/app-a/dist
and thats whats messing with me
Giant pandaOP
well, nx is special lol
what would the matrix look like?
like it would be manually running each of the apps individually (but at the same time), so you prob would loose nx features
so, i use turbo repo and it can cache folders inside your app project and save it to a global cache that can be used, does nx have something like it?
Giant pandaOP
unfortunately not, i'll do some research and come back with an answer hopefully