AWS Amplify Gen2 DX | Nextjs14 Fullstack Build
This is a Guide for Amplify code-first DX with Next js 14. - Offical AWS Amplify Documentation
Overview
The Offical AWS Amplify Documentation is pretty handy, it is easy to follow and kick start the project. This Guide will only coverage the deploy section .
Prerequisites
Before you get started, make sure you have the offical guide to the Step Deploy and host a fullstack branch and this is the tricky part step, grap a coffee and have a seat.
Build setting
By default, Amplify will konw that we are using nextjs and build your system with it. However, Amplify DX is using Amazon Linux 2 as the build image. By default it is using node Node.js 18.13.0. and Nextjs 14 is required node >= v18.17.0 . when you started to build it with nextjs 14 you will fall into this error.
# Completed phase: preBuild
# Starting phase: build
[INFO]: # Executing command: npm run build
[INFO]: > [email protected] build
> next build
[WARNING]: You are using Node.js 18.13.0. For Next.js, Node.js version >= v18.17.0 is required.
[ERROR]: !!! Build failed
If you are the preview AWS amplify user, you will go to modify the build setting.
However In Gen2, you will only see the amplify.yml
and cant found the custom image right now.
## amplify.yml
version: 1
backend:
phases:
build:
commands:
- nvm 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/**/*
Solution
Missing @parcel/watcher
The soultion to solve Missing @parcel/watcher
is easy, you will need to add the @parcel/watcher
as optionalDependencies.
npm i -O @parcel/watcher-linux-x64-glibc
Node version & GLIBC to 2.27
Create file named amplify.yml at your source folder.
#amplify.yml
version: 1
backend:
phases:
build:
commands:
- echo "### Downloading the NodeJS binary (x86 only)"
- wget -nv https://d3rnber7ry90et.cloudfront.net/linux-x86_64/node-v18.17.1.tar.gz
- mkdir -p /usr/local/lib/node
- tar -xf node-v18.17.1.tar.gz
- mv node-v18.17.1 /usr/local/lib/node/nodejs
- echo "### Configuring environment"
- echo "export NVM_DIR=''" >> ~/.bashrc
- echo "export NODEJS_HOME=/usr/local/lib/node/nodejs" >> ~/.bashrc
- echo "export PATH=\$NODEJS_HOME/bin:\$PATH" >> ~/.bashrc
- source ~/.bashrc
- echo "### Verifying NodeJS installation"
- node -e "console.log('Running Node.js ' + process.version)"
- 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/**/*
NODE_ENV error
It is easy to solve this. [WARNING]: ⚠ You are using a non-standard "NODE_ENV" value in your environment. This creates inconsistencies in the project and is strongly advised against. Read more: https://nextjs.org/docs/messages/non-standard-node-env
Remove the Node Env
What follows from here is just a bunch of absolute nonsense I've written to dogfood the plugin itself. It includes every sensible typographic element I could think of, like bold text, unordered lists, ordered lists, code blocks, block quotes, and even italics.
It's important to cover all of these use cases for a few reasons:
- We want everything to look good out of the box.
- Really just the first reason, that's the whole point of the plugin.
- Here's a third pretend reason though a list with three items looks more realistic than a list with two items.
Now we're going to try out another header style.
Typography should be easy
So that's a header for you — with any luck if we've done our job correctly that will look pretty reasonable.
Something a wise person once told me about typography is:
Typography is pretty important if you don't want your stuff to look like trash. Make it good then it won't be bad.
It's probably important that images look okay here by default as well:
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.
Now I'm going to show you an example of an unordered list to make sure that looks good, too:
- So here is the first item in this list.
- In this example we're keeping the items short.
- Later, we'll use longer, more complex list items.
And that's the end of this section.
What if we stack headings?
We should make sure that looks good, too.
Sometimes you have headings directly underneath each other. In those cases you often have to undo the top margin on the second heading because it usually looks better for the headings to be closer together than a paragraph followed by a heading should be.
When a heading comes after a paragraph …
When a heading comes after a paragraph, we need a bit more space, like I already mentioned above. Now let's see what a more complex list would look like.
-
I often do this thing where list items have headings.
For some reason I think this looks cool which is unfortunate because it's pretty annoying to get the styles right.
I often have two or three paragraphs in these list items, too, so the hard part is getting the spacing between the paragraphs, list item heading, and separate list items to all make sense. Pretty tough honestly, you could make a strong argument that you just shouldn't write this way.
-
Since this is a list, I need at least two items.
I explained what I'm doing already in the previous list item, but a list wouldn't be a list if it only had one item, and we really want this to look realistic. That's why I've added this second list item so I actually have something to look at when writing the styles.
-
It's not a bad idea to add a third item either.
I think it probably would've been fine to just use two items but three is definitely not worse, and since I seem to be having no trouble making up arbitrary things to type, I might as well include it.
After this sort of list I usually have a closing statement or paragraph, because it kinda looks weird jumping right to a heading.
Code should look okay by default.
I think most people are going to use highlight.js or Prism or something if they want to style their code blocks but it wouldn't hurt to make them look okay out of the box, even with no syntax highlighting.
Here's what a default tailwind.config.js
file looks like at the time of writing:
module.exports = {
purge: [],
theme: {
extend: {},
},
variants: {},
plugins: [],
}
Hopefully that looks good enough to you.
What about nested lists?
Nested lists basically always look bad which is why editors like Medium don't even let you do it, but I guess since some of you goofballs are going to do it we have to carry the burden of at least making it work.
- Nested lists are rarely a good idea.
- You might feel like you are being really "organized" or something but you are just creating a gross shape on the screen that is hard to read.
- Nested navigation in UIs is a bad idea too, keep things as flat as possible.
- Nesting tons of folders in your source code is also not helpful.
- Since we need to have more items, here's another one.
- I'm not sure if we'll bother styling more than two levels deep.
- Two is already too much, three is guaranteed to be a bad idea.
- If you nest four levels deep you belong in prison.
- Two items isn't really a list, three is good though.
- Again please don't nest lists if you want people to actually read your content.
- Nobody wants to look at this.
- I'm upset that we even have to bother styling this.
The most annoying thing about lists in Markdown is that <li>
elements aren't given a child <p>
tag unless there are multiple paragraphs in the list item. That means I have to worry about styling that annoying situation too.
-
For example, here's another nested list.
But this time with a second paragraph.
- These list items won't have
<p>
tags - Because they are only one line each
- These list items won't have
-
But in this second top-level list item, they will.
This is especially annoying because of the spacing on this paragraph.
-
As you can see here, because I've added a second line, this list item now has a
<p>
tag.This is the second line I'm talking about by the way.
-
Finally here's another list item so it's more like a list.
-
-
A closing list item, but with no nested list, because why not?
And finally a sentence to close off this section.
There are other elements we need to style
I almost forgot to mention links, like this link to the Tailwind CSS website. We almost made them blue but that's so yesterday, so we went with dark gray, feels edgier.
We even included table styles, check it out:
Wrestler | Origin | Finisher |
---|---|---|
Bret "The Hitman" Hart | Calgary, AB | Sharpshooter |
Stone Cold Steve Austin | Austin, TX | Stone Cold Stunner |
Randy Savage | Sarasota, FL | Elbow Drop |
Vader | Boulder, CO | Vader Bomb |
Razor Ramon | Chuluota, FL | Razor's Edge |
We also need to make sure inline code looks good, like if I wanted to talk about <span>
elements or tell you the good news about @tailwindcss/typography
.
Sometimes I even use code
in headings
Even though it's probably a bad idea, and historically I've had a hard time making it look good. This "wrap the code blocks in backticks" trick works pretty well though really.
Another thing I've done in the past is put a code
tag inside of a link, like if I wanted to tell you about the tailwindcss/docs
repository. I don't love that there is an underline below the backticks but it is absolutely not worth the madness it would require to avoid it.
We haven't used an h4
yet
But now we have. Please don't use h5
or h6
in your content, Medium only supports two heading levels for a reason, you animals. I honestly considered using a before
pseudo-element to scream at you if you use an h5
or h6
.
We don't style them at all out of the box because h4
elements are already so small that they are the same size as the body copy. What are we supposed to do with an h5
, make it smaller than the body copy? No thanks.
We still need to think about stacked headings though.
Let's make sure we don't screw that up with h4
elements, either.
Phew, with any luck we have styled the headings above this text and they look pretty good.
Let's add a closing paragraph here so things end with a decently sized block of text. I can't explain why I want things to end that way but I have to assume it's because I think things will look weird or unbalanced if there is a heading too close to the end of the document.
What I've written here is probably long enough, but adding this final sentence can't hurt.
GitHub Flavored Markdown
I've also added support for GitHub Flavored Mardown using remark-gfm
.
With remark-gfm
, we get a few extra features in our markdown. Example: autolink literals.
A link like www.example.com or https://example.com would automatically be converted into an a
tag.
This works for email links too: [email protected].