turbo
turbo copied to clipboard
Vercel documentation for turbo pruning a Next.js app
Describe the feature you'd like to request
There should be an example in Turbo and Vercel documentation about how to set up Vercel's 4 build fields: build
, install
, output directory
, and root directory
to work with turbo prune
, so that we can reduce build time significantly from installing unused packages as turbo run build --scope=<package>
does as documented here: https://vercel.com/docs/concepts/git/monorepos
turbo prune --scope=<package>
trims about 50% of my weight, but the builds fail on Vercel due to an error that the next
version cannot be found in the package.
Describe the solution you'd like
There should be clear documentation on pruning and Vercel that works with the default setup.
Describe alternatives you've considered
- Many permutations of build, install, output directory, and root directory.
- The root directory would need to be
out/apps/package
but it fails on VercelAnalyzing source code...
step presumably because it expects source code there before the install step which our first chance to prune.
Just found this: https://twitter.com/turborepo/status/1398026252620120064
This already works with @Vercel
1. Remove "Install Command"
2. Set your "Build Command" to install turbo, prune for the <target> app, cd into ./out, yarn install, turbo run build
3. Set output directory to /out/<target>/dist or whatever your output folder is
The Vercel docs have a Turborepo section, which gives an example build command:
cd ../.. && npx turbo run build --scope=<app> --includeDependencies --no-deps
Something to be careful of (emphasis mine):
where <app> is the directory path of the application (e.g. apps/docs)
I found just using the app name (e.g docs
) worked. If I used apps/docs
it built all apps and packages.
Prune config for Next.js turborepo app
Build: cd ./out && npx turbo run build --filter=<app>
(--scope is depricaated)
Output: /out/apps/<app>/.next
Install: yarn add turbo -DW && npx turbo prune --scope=<app> && cd ./out && yarn install
Root Directory: ./
@sannajammeh is correct. However, if you switch to pnpm, prune isn't necessary on Vercel since it can do a filtered install pnpm install --filter=docs...
So none of the above worked for me in PNPM.
running pnpm install --filter
doesn't actually do anything different to pnpm install
so for us we were still hitting the 13 gig limit.
Also only overriding the build command means that you are still doing a full install in the install step so its of no benefit.
After days of trial and error I finally come up with the follow that works. The install step breaks unless next.js is in the default working directory. So the key is to cp that into the right place to skip that check....
Install Command: turbo prune --scope=<app> && cd /vercel/path0/out && pnpm install && find . -type d -name "node_modules" -exec cp -r {} /vercel/path0/ \;
Build Command: cd /vercel/path0/out && turbo run build --filter=<app>
Output Directory: ../../out/<app path>/.next
Hope this saves someone else days of working this out.
Vercel does this all automatically, you can remove the custom install scripts and it will just work and filter.
It does not. I promise you :-)
It does not. I promise you :-)
@robbydooo I can promise you it does :) Also, pnpm --filter
needs to be configured correctly if you're manually overriding it. We have 8 projects all building in Vercel in the same monorepo hitting well above 13gb of node_modules in local development, but each project filters correctly (both with overridden install script and default vercel script).
This is the filtering installer for our admin panel in that same monorepo:
pnpm install --filter admin...
Vercel CLI 32.4.1
--
01:32:54.379 | > Detected Turbo. Adjusting default settings...
We have manually overridden it because it doesnt work. I have actually been working with the Vercel monorepo team on this directly.
The pnpm overide you mention installs way more to the node_modules vs turbo prune version.
I just reran your version and we are back to erroring out on running out of disk.