|
1 | 1 | --- |
2 | | -last_modified: 2026-06-16 |
| 2 | +last_modified: 2026-07-07 |
3 | 3 | title: "Build a Next.js App" |
4 | 4 | description: "Walkthrough guide to building a Next.js application with Deno. Learn how to set up a project, create API routes, implement server-side rendering, and build a full-stack TypeScript application." |
5 | 5 | url: /examples/next_tutorial/ |
@@ -57,6 +57,22 @@ compatibility, update your `deno.json` file with the following configuration: |
57 | 57 | } |
58 | 58 | ``` |
59 | 59 |
|
| 60 | +Next.js reads `next.config.*` during local and Deploy builds. With Deno, prefer |
| 61 | +an ESM config file named `next.config.mjs` or `next.config.ts`: |
| 62 | + |
| 63 | +```js title="next.config.mjs" |
| 64 | +/** @type {import('next').NextConfig} */ |
| 65 | +const nextConfig = {}; |
| 66 | + |
| 67 | +export default nextConfig; |
| 68 | +``` |
| 69 | + |
| 70 | +If you started from a scaffold that generated `next.config.js` with |
| 71 | +`module.exports`, Deno's `detect-cjs` option usually lets that CommonJS config |
| 72 | +work. If you still see `module is not defined`, or if a tool loads the config as |
| 73 | +an ES module, rename it to `next.config.mjs` and use `export default` as shown |
| 74 | +above. |
| 75 | + |
60 | 76 | Now install the dependencies found in the package.json: |
61 | 77 |
|
62 | 78 | ```sh |
@@ -178,9 +194,9 @@ export type Dino = { name: string; description: string }; |
178 | 194 | We'll update the `page.tsx` file in the `app` directory to fetch the dinosaur |
179 | 195 | data from our API and display it as a list of links. |
180 | 196 |
|
181 | | -To execute client-side code in Next.js we need to use the `use Client` directive |
182 | | -at the top of the file. Then we'll import the modules that we'll need in this |
183 | | -page and export the default function that will render the page: |
| 197 | +To execute client-side code in Next.js we need to use the `"use client"` |
| 198 | +directive at the top of the file. Then we'll import the modules that we'll need |
| 199 | +in this page and export the default function that will render the page: |
184 | 200 |
|
185 | 201 | ```tsx title="page.tsx" |
186 | 202 | "use client"; |
@@ -302,6 +318,20 @@ details! |
302 | 318 | Now that you have your working Next.js app, you can deploy it to the web with |
303 | 319 | Deno Deploy. |
304 | 320 |
|
| 321 | +:::tip Build troubleshooting |
| 322 | + |
| 323 | +If `next build` fails on Deno with |
| 324 | +`Cannot read properties of undefined (reading 'bold')`, the failure is in |
| 325 | +Next.js's build-time lint/type-check pass. A temporary workaround is to add |
| 326 | +`typescript.ignoreBuildErrors` and `eslint.ignoreDuringBuilds` to |
| 327 | +`next.config.mjs`, then run type checking and linting separately in CI. |
| 328 | + |
| 329 | +If a client component uses browser-only hooks or APIs, Next.js may still try to |
| 330 | +prerender it during the build. Move browser-only code behind a client-only |
| 331 | +boundary or make the route dynamic so it is not statically prerendered. |
| 332 | + |
| 333 | +::: |
| 334 | + |
305 | 335 | For the best experience, you can deploy your app directly from GitHub, which |
306 | 336 | will set up automated deployments. Create a GitHub repository and push your app |
307 | 337 | there. |
|
0 commit comments