-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot deploy Nextjs ssr app from an Nx monorepo #1866
Comments
Hi @estyh 👋, thanks for raising. I'm going to transfer to the Amplify Console repo to get some more eyes on it. |
Any updates? I got the same issue. |
I got also the same issue. I want to deploy multiple apps via amplify console so I can have one backend and multiple frontends. |
I've just hit this problem too. Is there any way to inspect the SSR process to see what the error is? |
I am also facing same issue please suggest the solution |
I've raised this on the Nx repo too to try to get some traction on this. For the moment, I'm having to restart my project using Lerna instead of Nx, which I'm really sad about 😢 . |
Hey @siegerts any updates? |
Hi all, we've recently made improvements to our SSR error logging and have added support for Next.js 10/11. |
I'm also facing the same issue
Any update on this? |
Same issue as well. Not using Nx, just using a standard next.js app inside of a monorepo. |
I'm getting this same error for a Next 11 build in a yarn 1 workspaces monorepo |
@tamagokun @j3lev @zeroonea @Schubidu can you please share sample repos if possible? we are struggling to repro the problem. |
@swaminator I don't get the same error, but I also cannot seem to figure out to get this to be an SSR app. It doesn't seem to be doing the SSR build in the build output when I deploy. https://github.com/tamagokun/next-amplify-monorepo-test UPDATE: I got this to work. It seems like the trick is to get Amplify to detect the correct framework. If it doesn't detect it as Detecting next.js SSR:
UPDATE 2: Another gotcha i've noticed is that the directory where you end up after the build step MUST be the root of the next.js workspace (NOT the root of the repo) For example:
|
Thanks for @tamagokun comment. According to https://docs.aws.amazon.com/amplify/latest/userguide/server-side-rendering-amplify.html#deploy-nextjs-app, we detect your app as a SSR app by inspecting your
You can add For folks who are using You can build by following build settings:
Feel free to reopen or comment if you have other questions |
@victorccccc Thanks for checking into this. I will test this out. I would like to point out that the documentation you linked to is not clear about the inspected package.json being in the monorepo root and that it's not intuitive on its own - I would recommend updating the docs. |
hi @estyh , thanks for your feedback, we will update the docs. |
or maybe better yet, allow the user to select the framework when creating the app. Detection is great for figuring out the "default", but not having a way to pick what one makes situations like this painful |
@victorccccc I updated my sample-repo (link in issue description) with the sample code in your comment. |
I've been looking at this post for hours now and I keep running into issues. I'm using monorepo setup with NX. I have a few questions. @victorccccc Why did you add the second step to go back into cd apps/reactapp and run npm install? I don't think it matters right? The only thing you need for SSR is the pkg JSON to make sure it uses SSR. Regarding the build process, why not run
|
|
@estyh Did you end up be able to deploy the NX monorepo? I've looked at all these different threads and I'm unable to deploy it. I change the hoist settings, modify the packages and none of it works. |
@Rafcin no, I also tried every possible solution and gave up after many wasted hours |
@estyh I see. Yea I've been struggling to deploy it as well. Did it blow up on I've been looking at this for a bit, maybe the solution would be to change the build command in the serverless file to point to the node_moduels/.bin/next folder in root. |
I don't remember the last thing it blew up on. I'm now deploying with the serverless nextjs plugin and it works perfectly. |
Interesting, I took a look at that but it seems a pain to go that way. I was really hoping NX would work but it just struggles at every turn when it comes to deployment. I'm really determined to find a solution. |
You can see my solution here, working great for me As an aside, I started using cdk for the backend instead of amplify, much more robust, and it has support for the serverless nextjs plugin. I haven't tried it yet, but I plan to, so that I can finally get fullstack deployments. |
@estyh are you able to share how you constructed your stack with NX and CDK? I started down an amplify route, but I'm increasingly thinking that CDK might be a better solution with NX. Especially as I am using CDK with the NestJS backend api already. |
I opened a ticket with the Amplify team. They are working on implementing support for NX. The date is unknown for the time (hopefully this month). Amplify also added the override feature so I think you'll be able to use CDK. |
@Rafcin cool, I'll keep my eyes open for that. |
Did you manage to deploy a monorepo app using lerna on AWS Amplify host? I was trying to deploy for a while, but always returns the following error in the deploy step: "Cannot find any generated SSR resources to deploy. If you intend for your app to be SSR, please check your app Service Role permissions. Otherwise, please check out our docs on how to setup your app to be detected as SSG (https://docs.aws.amazon.com/amplify/latest/userguide/server-side-rendering-amplify.html#deploy-nextjs-app)". Did you face the same problem? |
@luanbon if you moved from NX to lerna then redeploy by deleting the current hosted app and redeploy the same branches and it should work. I recommend Yarn workspaces if you plan to do it, but Lerna should work fine. Also don't use Next 12. |
@victorccccc your approach mostly works, but the build inside app/reactapp fails on shared libs components. Looks like it can't properly build dependent projects. Example error: |
@Rafcin do you know if the Amplify team successfully implemented support for Nx yet? |
I don't think so. I switched to Turbo for the time being. As far as I know, the entire build system is being overhauled, I'm guessing once that's done it should be fine. |
Turborepo might be a better option for a project as well paired with PNPM it's fantastic. If you choose to deploy it on Amplify it will work fine plus it's extremely fast. |
@Rafcin Sweet, I'll have to check it out. Thanks for the insight! |
@nozma-knows Heck yeah! I think you'll like Turborepo, it's fun to work with, and it often just works. Plus, it's made by Jared Palmer, and his packages are solid 😎 If you do use it, check out these links as well, I attached the turbo docks, the remote cache repo that I find super useful, and then two packages that use turbo that is well built! If you need any help with deploying on Amplify, let me know, I've been through all the rough issues. |
@Rafcin I'm trying to use turborepo with Next.js & Amplify. I encounter this error every time I try to use turborepo:
Here's
When I replace build command with |
@progexplorer24 So few things.
You seem to have a serverless error, I think it's because you don't have the build steps as I wrote them down. If the issue persists even after you change your build settings, contact the Amplify team on Discord or through a support ticket. They are the only ones who can see the serverless errors atm. Here is my amplify build for reference:
|
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Before opening, please confirm:
How did you install the Amplify CLI?
npm
If applicable, what version of Node.js are you using?
14.15.3
Amplify CLI Version
4.51.1
What operating system are you using?
Windows 10
Amplify Categories
hosting
Amplify Commands
Not applicable
Describe the bug
I am trying to deploy a nextjs ssr app to amplify. The app is in an nx monorepo. The build fails at the very end without any explanation.
sample repo here: https://github.com/estyh/ssr-nx
with sample amplify appid dqsfqet8cqqaj
region us-east-1
Expected behavior
Expect the build to succeed and get an amplify hosted ssr app!
Reproduction steps
npx create-nx-workspace@latest
create new nx workspace, use the nextjs templatenx run <appname>:build:production
this will run a prod build and put the output into dist/apps/copy the package.json from the dist folder into the nextjs app folder, and add a script "build":"next build" - this helps amplify to identify it later as an ssr app.
cd into the nextjs app folder
amplify init
- accept all the defaultsin the repo root, add amplify.yml with the following code:
commit and push to github
In the amplify console, select the new amplify app, and add a frontend. Connect to the repo, choose the monorepo option, and select the root as 'apps/'
Amplify should auto-detect the next-ssr framework and attempt a build.
It fails...
GraphQL schema(s)
No response
Log output
Additional information
My first amplify.yml attempt did not include
cd apps/nextapp
after the nx build command. This resulted in a different error:Here is a link to nx docs on how to deploy nextjs app to vercel: https://nx.dev/latest/react/guides/nextjs#deploying-to-vercel
And here is a post about deploying to heroku via containers: https://blog.nrwl.io/painlessly-build-and-deploy-next-js-apps-with-nx-225e2721da78
I would love if I could deploy to amplify!
The text was updated successfully, but these errors were encountered: