sladg / nextjs-lambda

Lambda deployments for Nextjs12 & Nextjs13 (standalone). Easy CLI commands to get your standalone Next output to run in AWS Lambda (not @Edge)! Uses CDK in behind and produces code zips importable to Terraform, Serverless, Azure, etc.
MIT License
169 stars 19 forks source link

When using pnpm in monorepo, cannot find next-sever.js in the main lambda #50

Closed adamsh25 closed 1 year ago

adamsh25 commented 1 year ago

Issue: Cannot find next-sever.js in the main lambda Remarks: Works OK for yarn monorepo Stack:

Followed guids: _Monorepos In case you are using monorepo, there are few more requirements. Firstly, you need to setup outputFileTracing in your next.config.js see: https://github.com/vercel/next.js/issues/36386#issuecomment-1137665939.

Secondly, you need to setup hoistingLimits: workspace. We need node_modules to actually contain all the dependencies in order for NextJS to pick them up for standalone build.

Tested with Turbo@1.5.5 and Yarn@3.2.4_

adamsh25 commented 1 year ago

Seems like pnpm adds to the dependenciesLayer.zip the dependencies with the version and yarn does not do this. I started a project from scratch using turbo: https://turbo.build/repo/docs/getting-started/create-new pnpm next.out:

image

yarn next.out

image
sladg commented 1 year ago

Hey! So I took a look. The problem is with pnpm itself not being really supported by Next's standalone output.

https://github.com/vercel/next.js/discussions/38435 https://stackoverflow.com/questions/70895922/pnpm-linking-with-standalone-nextjs-build https://github.com/vercel/next.js/discussions/40482

Overall it seems like a lot of fiddling to get it to work with breaking changes happening every half a year, from what I found. I'm gonna do some more work on monorepos, but I don't plan to support pnpm specifically in the near future. Feel free to share your findings, might get back to it later!