404 error with AWS Amplify and Next.js 14 deployment
Answered
Masai Lion posted this in #help-forum
Masai LionOP
I'm having trouble with deploying my Next.js 14 app on AWS Amplify. Everything works fine on my local machine, but when I deploy to Amplify, I receive a "Failed to load resource: the server responded with a status of 404 ()" error.
Here's what I've done so far:
Configured my Amplify project to use a custom build image with support for Next.js 14 features (amplify:al2023).
Ensured that all my routes and resource links are correct and working locally.
Checked my build settings on Amplify to make sure the base directory and artifact settings are correctly pointing to my .next folder.
Here is my amplify.yml file:
Despite this, I keep getting a 404 error when accessing the website, and I can't seem to figure out why. Has anyone else encountered this issue, or does anyone have any insights on what might be going wrong?
Any help or guidance would be greatly appreciated!
Here's what I've done so far:
Configured my Amplify project to use a custom build image with support for Next.js 14 features (amplify:al2023).
Ensured that all my routes and resource links are correct and working locally.
Checked my build settings on Amplify to make sure the base directory and artifact settings are correctly pointing to my .next folder.
Here is my amplify.yml file:
version: 1
frontend:
phases:
preBuild:
commands:
- nvm install 20
- nvm use 20
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
image:
buildImage: 'amplify:al2023'
Despite this, I keep getting a 404 error when accessing the website, and I can't seem to figure out why. Has anyone else encountered this issue, or does anyone have any insights on what might be going wrong?
Any help or guidance would be greatly appreciated!
Answered by Masai Lion
Hi @Anay-208 | Ping on replies
This solved the problem:
https://stackoverflow.com/questions/77292174/intl-localematcher-in-next-js-rangeerror-incorrect-locale-information-provided
This solved the problem:
https://stackoverflow.com/questions/77292174/intl-localematcher-in-next-js-rangeerror-incorrect-locale-information-provided
41 Replies
@Anay-208 | Ping on replies are you using amplify gen2?
Masai LionOP
Nope. I'm recreating the app using gen 2 now...
ignore it, I'm sending you new content for amplify.yml
@Anay-208 | Ping on replies https://github.com/anay-208/portfolio/blob/main/amplify.yml
Masai LionOP
It solved the problem with 404, but it's giving a 500 now
@Masai Lion It solved the problem with 404, but it's giving a 500 now
If you’ve a git repo, that’d help
Alr, I'll check
@Anay-208 | Ping on replies Alr, I'll check
Masai LionOP
tnx
@Masai Lion tnx
where is the amplify.yml
Masai LionOP
I edited the amplify.yml in build settings on AWS console
@Masai Lion I edited the amplify.yml in build settings on AWS console
its best to add it to git repo
amplify.yml
Masai LionOP
Do you wanna me to add it to the git repo?
You can add it later on
Masai LionOP
okay
@Masai Lion okay
I've forked the repo & I'm testing it by deploying on amplify. I'll let you know if I find the issue(if any).
and you're using amplify gen2 only, right?
Masai LionOP
yup, I'm using amplify gen2
@Masai Lion yup, I'm using amplify gen2
was your build successful in Aws amplify console?
Masai LionOP
Yes. But I had to use the amazon linux 2023 image
@Masai Lion Yes. But I had to use the amazon linux 2023 image
how did you change the image in amplify console?
Masai LionOP
Strange. The UI changed and I can't find where I changed the image, but it was in build settings. But you can change the image by adding
in the yml file
image:
buildImage: 'amplify:al2023'
in the yml file
Masai LionOP
version: 1
backend:
phases:
build:
commands:
- nvm install 20
- nvm use 20
- npm ci
- npx amplify pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
image:
buildImage: 'amplify:al2023'
Once its deployed, I'll see the error.
Masai LionOP
exactly
I think there is something to do with the
middleware.ts
I once remember seeing something related to middlewares on the doc, let me see
@Masai Lion exactly
Did you got this error while building on amplify?
49
2024-01-14T16:28:20.481Z [INFO]: # Executing command: npm ci
50
2024-01-14T16:28:20.481Z [WARNING]: node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
51
node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)
52
2024-01-14T16:28:20.482Z [ERROR]: !!! Build failed
I just believe its a problem on amplify end, due to the latest stable version. the last stable version didn't had any issues
I believe its a problem on amplify end, even if I try to deploy nextjs-starter app, even that build fails
@Masai Lion
version: 1
backend:
phases:
build:
commands:
- nvm install 20
- nvm use 20
- npm ci
- npx amplify pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run build
artifacts:
baseDirectory: .next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
image:
buildImage: 'amplify:al2023'
Masai LionOP
I got this error before putting the last 2 lines of this
I'll let you know more details in a day or 2
Masai LionOP
okay, tnx!
If you solve this, Just let me know. I'm looking into this issue. My other projects are also affected by it.
@Anay-208 | Ping on replies If you solve this, Just let me know. I'm looking into this issue. My other projects are also affected by it.
Masai LionOP
Sure! I'm on vacation and have free time to try to solve this problem.
I'll let you know if I find anything
I'll let you know if I find anything
Masai LionOP
Hi @Anay-208 | Ping on replies
This solved the problem:
https://stackoverflow.com/questions/77292174/intl-localematcher-in-next-js-rangeerror-incorrect-locale-information-provided
This solved the problem:
https://stackoverflow.com/questions/77292174/intl-localematcher-in-next-js-rangeerror-incorrect-locale-information-provided
Answer