turbo icon indicating copy to clipboard operation
turbo copied to clipboard

Vercel documentation for turbo pruning a Next.js app

Open yuchant opened this issue 3 years ago • 10 comments

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.

image

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 Vercel Analyzing source code... step presumably because it expects source code there before the install step which our first chance to prune.

yuchant avatar Jan 06 '22 05:01 yuchant

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

yuchant avatar Jan 06 '22 06:01 yuchant

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.

steven-mercatante avatar Feb 03 '22 02:02 steven-mercatante

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 avatar Apr 16 '22 14:04 sannajammeh

@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...

jaredpalmer avatar Apr 20 '22 12:04 jaredpalmer

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.

robbydooo avatar Oct 19 '23 10:10 robbydooo

Vercel does this all automatically, you can remove the custom install scripts and it will just work and filter.

sannajammeh avatar Oct 19 '23 10:10 sannajammeh

It does not. I promise you :-)

robbydooo avatar Oct 19 '23 14:10 robbydooo

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...

image image


Vercel CLI 32.4.1
--
01:32:54.379 | > Detected Turbo. Adjusting default settings...

sannajammeh avatar Oct 19 '23 17:10 sannajammeh

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.

Screenshot 2023-10-19 at 22 09 22

robbydooo avatar Oct 19 '23 22:10 robbydooo

Screenshot 2024-05-23 at 12 22 17 PM This is what eventually worked for me

TylerJNewman avatar May 23 '24 19:05 TylerJNewman