When using pnpm in monorepo, cannot find next-sever.js in the main lambda
adamsh25 opened this issue · comments
Issue:
Cannot find next-sever.js in the main lambda
Remarks:
Works OK for yarn monorepo
Stack:
- Next@12.3.2
- Turbo@1.5.5
- pnpm@7.13.5
- sladg/nextjs-lambda@v3.20.3
Error:
{ "errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module 'next/dist/server/next-server'\nRequire stack:\n- /var/task/handler.js\n- /var/runtime/index.mjs", "stack": [ "Runtime.ImportModuleError: Error: Cannot find module 'next/dist/server/next-server'", "Require stack:", "- /var/task/handler.js", "- /var/runtime/index.mjs", " at _loadUserApp (file:///var/runtime/index.mjs:951:17)", " at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:976:21)", " at async start (file:///var/runtime/index.mjs:1137:23)", " at async file:///var/runtime/index.mjs:1143:1" ] }
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: vercel/next.js#36386 (comment).
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_
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:
yarn next.out
Hey!
So I took a look. The problem is with pnpm
itself not being really supported by Next's standalone output.
vercel/next.js#38435
https://stackoverflow.com/questions/70895922/pnpm-linking-with-standalone-nextjs-build
vercel/next.js#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!