amplify-hosting icon indicating copy to clipboard operation
amplify-hosting copied to clipboard

!!! CustomerError: Can't find required-server-files.json in build output directory

Open Quska45 opened this issue 1 year ago • 15 comments
trafficstars

Quska45 avatar Dec 21 '23 07:12 Quska45

I've also been experiencing the error "CustomerError: Can't find required-server-files.json in build output directory" for the past week on my Nextjs app. It doesn't seem to be related to any changes I've made, as I've sometimes been able to revert and then re-add commits to achieve a successful build, only to run into the same issue a few commits later.

This is now completely blocking my deployments.

alexandersg2 avatar Dec 22 '23 03:12 alexandersg2

Same issue here, Any response yet from Amplify team?

rayedturbine avatar Dec 22 '23 22:12 rayedturbine

Any updates on this? I've been unable to deploy new code for 2 weeks now and am getting desperate. If the Amplify team can't look into this, can anyone tell me the next best way to deploy an Amplify app? Cheers

alexandersg2 avatar Dec 28 '23 03:12 alexandersg2

I seem to have fixed the issue by updating the line **/*.js to src/**/*.js in my tsconfig.json.

alexandersg2 avatar Dec 30 '23 06:12 alexandersg2

I am also getting this problem. The solution to update **/*.js to src/**/*.js did not work for me. Can Amplify team look into this?

abe123442 avatar Jan 27 '24 03:01 abe123442

Got the same error after successful build of Next.js application :)

I use Next.js v14 with { output: "export" } config.

I run on custom build image with Node 20: public.ecr.aws/docker/library/node:20.11.0

karpolan avatar Jan 27 '24 19:01 karpolan

The problem is if you are using ‘next’ or yarn dev/run dev for tests then the build (.next) is overriden and doesnt have production build anymore. Make sure you either use production build or run next build after completing tests or tests server.

Thank you,

Rayed bajwa


From: Anton Karpenko @.> Sent: Saturday, January 27, 2024 2:55:19 PM To: aws-amplify/amplify-hosting @.> Cc: Rayed Bajwa @.>; Manual @.> Subject: Re: [aws-amplify/amplify-hosting] !!! CustomerError: Can't find required-server-files.json in build output directory (Issue #3869)

Got the same error after successful build of Next.js application :)

I use Next.js v14 with { output: "export" } config.

I run on custom build image with Node 20: public.ecr.aws/docker/library/node:20.11.0

— Reply to this email directly, view it on GitHubhttps://github.com/aws-amplify/amplify-hosting/issues/3869#issuecomment-1913314040, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BAH3BL67QHDUCXZIFUFEM7TYQVLSPAVCNFSM6AAAAABA57AKSSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJTGMYTIMBUGA. You are receiving this because you are subscribed to this thread.Message ID: @.***>

rayedturbine avatar Jan 27 '24 19:01 rayedturbine

~~The issue disappears if change baseDirectory from "out" back to default ".next"~~

P.S. I also changed the building image to "Amazon Linux:2023"

image

karpolan avatar Jan 27 '24 20:01 karpolan

LOL, but after a successful build and deployment, the website is not working...

I love Apmlify (c)

karpolan avatar Jan 27 '24 20:01 karpolan

Any updates on this? Still facing the problem

NickRumenov avatar Jan 29 '24 09:01 NickRumenov

I'm facing this issue as well with next 14.1.4 app with SSG pages hosted on amplify.

The next docs are explicit about using output: "export" in my next.config.js and that it will output to out folder: https://nextjs.org/docs/app/building-your-application/deploying/static-exports

It builds locally but with my build settings like this, getting the Can't find required-server-files.json error on amplify.

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - npm ci
    build:
      commands:
        - npm run build
  artifacts:
    baseDirectory: out
    files:
      - '**/*'
  cache:
    paths:
      - .next/cache/**/*
      - node_modules/**/*

dancj avatar Apr 05 '24 17:04 dancj

I faced a similar problem when trying to host static Storybook files which is in Next.js dir. My issue was resolved by switching the platform from WEB_COMPUTE to WEB using the CLI.

aws amplify update-app --app-id your-amplify-app-id --platform WEB --region your-region

Reference: https://docs.aws.amazon.com/amplify/latest/userguide/redeploy-ssg-to-ssr.html#update-platform

Hopefully it could be helpful.

isoppp avatar Jun 12 '24 11:06 isoppp

Yes the baseDirectory: .next will not running correctly if you want to build a NextJS - SSG, static site generating.

So basically you may need to change it to baseDirectory: out in the amplify.yml, also don't use next export, because it no longer supported by NextJS from v13.4.0 and has been removed from `v14.0.0, which will causing error when building in AWS Amplify (Reference

You will need to use out: "export" in you next.config.js file, in the nextConfig. You can try to build from here

And then if your build still causing error, maybe because Amplify does not recognise your app as a SSR or SSG, so you might need to go to AWS CLI to configure

Remember to create an IAM account with the correct provision rules to work with Amplifier

  1. Run the following AWS CLI commands
aws amplify update-app --app-id <APP_ID> --platform WEB --region <REGION>
aws amplify update-branch --app-id <APP_ID> --branch-name <BRANCH_NAME> --framework 'Next.js - SSG' --region <REGION>
  1. Update your build spec to point the baseDirectory to out. e.g.
version: 1
frontend:
  ...
  artifacts:
    baseDirectory: out
  ...
  1. Trigger rebuild through commit, or manually

  2. You ready to go

Sometime the URL by Amplify, for example the built one is mysite.com, but when you clicked it appear nothing, actually because the actual routes is mysite.com/index.html

So if you want to set up the URL, You can go to the AWS Amplify Hosting console, go under All app / <Your Repo Name> / Hosting, and go to the Rewrites and redirects tab.

Then for example, if you want:

mysite.com/index.html -> mysite.com

You can set:

Source URL Target URL Type Country Code
/index.html / 200 (Rewrite) <Can be blank>

If you have some other routes, like /example.html but you dont want the .html ending, you can do this

mysite.com/example.html -> mysite.com/example

Source URL Target URL Type Country Code
/<any>.html /<any> 200(Rewrite) <Can be blank>

Thats my initial approach, hope that it is useful. Peace!

pvhuwung avatar Jun 20 '24 10:06 pvhuwung

Hi there, three months ago. I have the same bug. I know a way to remedy that bug. 

I have explained it here: 

  • https://github.com/aws-amplify/amplify-hosting/issues/3872#issuecomment-1980806305

Check it out here:

  • https://datnguyennnx.github.io/4-amplifyhosting/ 
  • https://datnguyennnx.github.io/4-amplifyhosting/4.1-deploycode/

It's helpful for you. Leave a thumbs up for me to know you solved it. 

datnguyennnx avatar Jun 20 '24 14:06 datnguyennnx