aws-amplify / amplify-hosting

AWS Amplify Hosting provides a Git-based workflow for deploying and hosting fullstack serverless web applications.
https://aws.amazon.com/amplify/hosting/
Apache License 2.0
461 stars 116 forks source link

Next.js Deployment Issues on AWS Amplify: <Html> Import Errors and useContext Null Property Errors #3944

Closed mashwishi closed 4 months ago

mashwishi commented 5 months ago

Before opening, please confirm:

Amplify Hosting feature

Deployments

Is your feature request related to a problem? Please describe:

We are experiencing several issues during the build phase of our Next.js application deployment on AWS Amplify. These issues include:

  1. import outside of pages/_document: We are encountering errors where components are being imported outside of the pages/_document file. According to Next.js documentation (https://nextjs.org/docs/messages/no-document-import-in-page), should only be used within _document.js and not within regular pages. - I am using app directory and don't have pages/_document and have touch anything that much in the code of create-next-app with next-auth ```tsx import type { Metadata } from "next";

import { Inter } from "next/font/google"; import { Toaster } from "react-hot-toast";

import { SessionProvider } from "next-auth/react"; import { Providers } from "./providers";

import "./globals.css";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = { title: process.env.NEXT_PUBLIC_SITE_NAME || "Create Next App", description: "Generated by create next app", };

export default function RootLayout({ children, }: Readonly<{ children: React.ReactNode; }>) { return ( //

{children}

); }


2. TypeError: Cannot read properties of null (reading 'useContext'): This error is occurring intermittently, particularly on pages that involve useContext. It's unclear why this error is happening, as our codebase adheres to React's useContext guidelines and works correctly in local development environments.
- Also don't know why it's throwing TypeError

3. Other static page generation errors: Additionally, we are seeing errors related to static page generation, particularly on paths like /404, /500, and custom pages such as /dashboard, /login, /register, and others.
- For /404 and /500 We don't have this page and for the /dashboard, /login, /register, and others, I have tried building it and haven't found the same issue as amplify throwing in the log.

Build Log:
```bat
024-06-27T10:03:09.774Z [INFO]: # Completed phase: preBuild
                                 # Starting phase: build
                                 # Executing command: yarn run build
2024-06-27T10:03:09.931Z [INFO]: yarn run v1.22.19
2024-06-27T10:03:09.954Z [INFO]: $ next build
2024-06-27T10:03:10.026Z [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
2024-06-27T10:03:10.693Z [INFO]: ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
2024-06-27T10:03:10.707Z [INFO]: Attention: Next.js now collects completely anonymous telemetry regarding usage.
2024-06-27T10:03:10.708Z [INFO]: This information is used to shape Next.js' roadmap and prioritize features.
                                 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
                                 https://nextjs.org/telemetry
2024-06-27T10:03:10.775Z [INFO]: ▲ Next.js 14.2.4
2024-06-27T10:03:10.775Z [INFO]: 
2024-06-27T10:03:10.854Z [INFO]: Creating an optimized production build ...
2024-06-27T10:03:13.077Z [WARNING]: Warning: You're using `next/head` inside the `app` directory, please migrate to the Metadata API. See https://nextjs.org/docs/app/building-your-application/upgrading/app-router-migration#step-3-migrating-nexthead for more details.
2024-06-27T10:03:26.585Z [WARNING]: ⚠ Compiled with warnings
2024-06-27T10:03:26.591Z [WARNING]: ./node_modules/bcryptjs/dist/bcrypt.js
                                    A Node.js API is used (process.nextTick at line: 351) which is not supported in the Edge Runtime.
                                    Learn more: https://nextjs.org/docs/api-reference/edge-runtime
                                    Import trace for requested module:
                                    ./node_modules/bcryptjs/dist/bcrypt.js
                                    ./auth.ts
                                    ./node_modules/bcryptjs/dist/bcrypt.js
                                    A Node.js API is used (setImmediate at line: 352) which is not supported in the Edge Runtime.
                                    Learn more: https://nextjs.org/docs/api-reference/edge-runtime
                                    Import trace for requested module:
                                    ./node_modules/bcryptjs/dist/bcrypt.js
                                    ./auth.ts
                                    ./node_modules/bcryptjs/dist/bcrypt.js
                                    A Node.js API is used (setImmediate at line: 352) which is not supported in the Edge Runtime.
                                    Learn more: https://nextjs.org/docs/api-reference/edge-runtime
                                    Import trace for requested module:
                                    ./node_modules/bcryptjs/dist/bcrypt.js
                                    ./auth.ts
                                    ./node_modules/bcryptjs/dist/bcrypt.js
                                    A Node.js API is used (process.nextTick at line: 352) which is not supported in the Edge Runtime.
                                    Learn more: https://nextjs.org/docs/api-reference/edge-runtime
                                    Import trace for requested module:
                                    ./node_modules/bcryptjs/dist/bcrypt.js
                                    ./auth.ts
2024-06-27T10:03:40.637Z [INFO]: ✓ Compiled successfully
2024-06-27T10:03:40.642Z [INFO]: Linting and checking validity of types ...
2024-06-27T10:03:45.893Z [INFO]: Collecting page data ...
2024-06-27T10:03:47.701Z [INFO]: Generating static pages (0/15) ...
2024-06-27T10:03:48.067Z [WARNING]: Error: <Html> should not be imported outside of pages/_document.
                                    Read more: https://nextjs.org/docs/messages/no-document-import-in-page
                                    at Z (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:16:5430)
                                    at I (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/682.js:6:1263)
                                    at renderWithHooks (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5658:16)
                                    at renderIndeterminateComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5732:15)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5957:7)
                                    at renderNodeDestructiveImpl (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6115:11)
                                    at renderNodeDestructive (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6087:14)
                                    at finishClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5688:3)
                                    at renderClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5696:3)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5954:7)
                                    Error occurred prerendering page "/500". Read more: https://nextjs.org/docs/messages/prerender-error
                                    Error: <Html> should not be imported outside of pages/_document.
                                    Read more: https://nextjs.org/docs/messages/no-document-import-in-page
                                    at Z (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:16:5430)
                                    at I (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/682.js:6:1263)
                                    at renderWithHooks (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5658:16)
                                    at renderIndeterminateComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5732:15)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5957:7)
                                    at renderNodeDestructiveImpl (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6115:11)
                                    at renderNodeDestructive (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6087:14)
                                    at finishClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5688:3)
                                    at renderClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5696:3)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5954:7)
2024-06-27T10:03:48.068Z [INFO]: Generating static pages (3/15)
2024-06-27T10:03:48.188Z [WARNING]: Error: <Html> should not be imported outside of pages/_document.
                                    Read more: https://nextjs.org/docs/messages/no-document-import-in-page
                                    at Z (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:16:5430)
                                    at I (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/682.js:6:1263)
                                    at renderWithHooks (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5658:16)
                                    at renderIndeterminateComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5732:15)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5957:7)
                                    at renderNodeDestructiveImpl (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6115:11)
                                    at renderNodeDestructive (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6087:14)
                                    at finishClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5688:3)
                                    at renderClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5696:3)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5954:7)
                                    Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error
                                    Error: <Html> should not be imported outside of pages/_document.
                                    Read more: https://nextjs.org/docs/messages/no-document-import-in-page
                                    at Z (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:16:5430)
                                    at I (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/682.js:6:1263)
                                    at renderWithHooks (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5658:16)
                                    at renderIndeterminateComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5732:15)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5957:7)
                                    at renderNodeDestructiveImpl (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6115:11)
                                    at renderNodeDestructive (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6087:14)
                                    at finishClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5688:3)
                                    at renderClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5696:3)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5954:7)
2024-06-27T10:03:48.214Z [WARNING]: TypeError: Cannot read properties of null (reading 'useContext')
                                    at t.useContext (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:109363)
                                    at d (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/317.js:1:21495)
                                    at h (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/317.js:1:13448)
                                    at au (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:10446)
                                    at /codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:15122
                                    at aw (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16908)
                                    at a_ (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:49776)
                                    at ab (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:11808)
                                    at /codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16871
                                    at aw (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16908) {
                                    digest: '3984810264'
                                    }
                                    TypeError: Cannot read properties of null (reading 'useContext')
                                    at t.useContext (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:109363)
                                    at d (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/317.js:1:21495)
                                    at h (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/317.js:1:13448)
                                    at au (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:10446)
                                    at /codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:15122
                                    at aw (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16908)
                                    at a_ (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:49776)
                                    at ab (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:11808)
                                    at /codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16871
                                    at aw (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16908)
                                    Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
                                    TypeError: Cannot read properties of null (reading 'useContext')
                                    at t.useContext (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:109363)
                                    at d (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/317.js:1:21495)
                                    at h (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/317.js:1:13448)
                                    at au (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:10446)
                                    at /codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:15122
                                    at aw (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16908)
                                    at a_ (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:49776)
                                    at ab (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:11808)
                                    at /codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16871
                                    at aw (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16908)
.
.
.
.
.
.
.
2024-06-27T10:03:48.432Z [INFO]: ✓ Generating static pages (15/15)
2024-06-27T10:03:48.437Z [WARNING]: 
2024-06-27T10:03:48.437Z [WARNING]: > Export encountered errors on following paths:
                                    /_error: /404
                                    /_error: /500
                                    /_not-found/page: /_not-found
                                    /client-side/page: /client-side
                                    /dashboard/page: /dashboard
                                    /example/page: /example
                                    /login/page: /login
                                    /page: /
                                    /profile/page: /profile
                                    /register/page: /register
2024-06-27T10:03:48.470Z [WARNING]: error Command failed with exit code 1.
2024-06-27T10:03:48.470Z [INFO]: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
2024-06-27T10:03:48.483Z [ERROR]: !!! Build failed
2024-06-27T10:03:48.483Z [INFO]: Please read more about Amplify Hosting's support for SSR frameworks to find if your build failure is related to an unsupported feature: https://docs.aws.amazon.com/amplify/latest/userguide/amplify-ssr-framework-support.html. You may also find this troubleshooting guide useful: https://docs.aws.amazon.com/amplify/latest/userguide/troubleshooting-ssr-deployment.html
2024-06-27T10:03:48.483Z [ERROR]: !!! Error: Command failed with exit code 1
2024-06-27T10:03:48.483Z [INFO]: # Starting environment caching...
2024-06-27T10:03:48.483Z [INFO]: # Environment caching completed
``````bat
024-06-27T10:03:09.774Z [INFO]: # Completed phase: preBuild
                                 # Starting phase: build
                                 # Executing command: yarn run build
2024-06-27T10:03:09.931Z [INFO]: yarn run v1.22.19
2024-06-27T10:03:09.954Z [INFO]: $ next build
2024-06-27T10:03:10.026Z [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
2024-06-27T10:03:10.693Z [INFO]: ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
2024-06-27T10:03:10.707Z [INFO]: Attention: Next.js now collects completely anonymous telemetry regarding usage.
2024-06-27T10:03:10.708Z [INFO]: This information is used to shape Next.js' roadmap and prioritize features.
                                 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
                                 https://nextjs.org/telemetry
2024-06-27T10:03:10.775Z [INFO]: ▲ Next.js 14.2.4
2024-06-27T10:03:10.775Z [INFO]: 
2024-06-27T10:03:10.854Z [INFO]: Creating an optimized production build ...
2024-06-27T10:03:13.077Z [WARNING]: Warning: You're using `next/head` inside the `app` directory, please migrate to the Metadata API. See https://nextjs.org/docs/app/building-your-application/upgrading/app-router-migration#step-3-migrating-nexthead for more details.
2024-06-27T10:03:26.585Z [WARNING]: ⚠ Compiled with warnings
2024-06-27T10:03:26.591Z [WARNING]: ./node_modules/bcryptjs/dist/bcrypt.js
                                    A Node.js API is used (process.nextTick at line: 351) which is not supported in the Edge Runtime.
                                    Learn more: https://nextjs.org/docs/api-reference/edge-runtime
                                    Import trace for requested module:
                                    ./node_modules/bcryptjs/dist/bcrypt.js
                                    ./auth.ts
                                    ./node_modules/bcryptjs/dist/bcrypt.js
                                    A Node.js API is used (setImmediate at line: 352) which is not supported in the Edge Runtime.
                                    Learn more: https://nextjs.org/docs/api-reference/edge-runtime
                                    Import trace for requested module:
                                    ./node_modules/bcryptjs/dist/bcrypt.js
                                    ./auth.ts
                                    ./node_modules/bcryptjs/dist/bcrypt.js
                                    A Node.js API is used (setImmediate at line: 352) which is not supported in the Edge Runtime.
                                    Learn more: https://nextjs.org/docs/api-reference/edge-runtime
                                    Import trace for requested module:
                                    ./node_modules/bcryptjs/dist/bcrypt.js
                                    ./auth.ts
                                    ./node_modules/bcryptjs/dist/bcrypt.js
                                    A Node.js API is used (process.nextTick at line: 352) which is not supported in the Edge Runtime.
                                    Learn more: https://nextjs.org/docs/api-reference/edge-runtime
                                    Import trace for requested module:
                                    ./node_modules/bcryptjs/dist/bcrypt.js
                                    ./auth.ts
2024-06-27T10:03:40.637Z [INFO]: ✓ Compiled successfully
2024-06-27T10:03:40.642Z [INFO]: Linting and checking validity of types ...
2024-06-27T10:03:45.893Z [INFO]: Collecting page data ...
2024-06-27T10:03:47.701Z [INFO]: Generating static pages (0/15) ...
2024-06-27T10:03:48.067Z [WARNING]: Error: <Html> should not be imported outside of pages/_document.
                                    Read more: https://nextjs.org/docs/messages/no-document-import-in-page
                                    at Z (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:16:5430)
                                    at I (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/682.js:6:1263)
                                    at renderWithHooks (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5658:16)
                                    at renderIndeterminateComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5732:15)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5957:7)
                                    at renderNodeDestructiveImpl (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6115:11)
                                    at renderNodeDestructive (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6087:14)
                                    at finishClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5688:3)
                                    at renderClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5696:3)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5954:7)
                                    Error occurred prerendering page "/500". Read more: https://nextjs.org/docs/messages/prerender-error
                                    Error: <Html> should not be imported outside of pages/_document.
                                    Read more: https://nextjs.org/docs/messages/no-document-import-in-page
                                    at Z (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:16:5430)
                                    at I (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/682.js:6:1263)
                                    at renderWithHooks (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5658:16)
                                    at renderIndeterminateComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5732:15)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5957:7)
                                    at renderNodeDestructiveImpl (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6115:11)
                                    at renderNodeDestructive (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6087:14)
                                    at finishClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5688:3)
                                    at renderClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5696:3)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5954:7)
2024-06-27T10:03:48.068Z [INFO]: Generating static pages (3/15)
2024-06-27T10:03:48.188Z [WARNING]: Error: <Html> should not be imported outside of pages/_document.
                                    Read more: https://nextjs.org/docs/messages/no-document-import-in-page
                                    at Z (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:16:5430)
                                    at I (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/682.js:6:1263)
                                    at renderWithHooks (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5658:16)
                                    at renderIndeterminateComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5732:15)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5957:7)
                                    at renderNodeDestructiveImpl (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6115:11)
                                    at renderNodeDestructive (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6087:14)
                                    at finishClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5688:3)
                                    at renderClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5696:3)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5954:7)
                                    Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error
                                    Error: <Html> should not be imported outside of pages/_document.
                                    Read more: https://nextjs.org/docs/messages/no-document-import-in-page
                                    at Z (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/pages.runtime.prod.js:16:5430)
                                    at I (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/682.js:6:1263)
                                    at renderWithHooks (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5658:16)
                                    at renderIndeterminateComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5732:15)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5957:7)
                                    at renderNodeDestructiveImpl (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6115:11)
                                    at renderNodeDestructive (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6087:14)
                                    at finishClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5688:3)
                                    at renderClassComponent (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5696:3)
                                    at renderElement (/codebuild/output/src3157314800/src/Prod-App/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5954:7)
2024-06-27T10:03:48.214Z [WARNING]: TypeError: Cannot read properties of null (reading 'useContext')
                                    at t.useContext (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:109363)
                                    at d (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/317.js:1:21495)
                                    at h (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/317.js:1:13448)
                                    at au (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:10446)
                                    at /codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:15122
                                    at aw (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16908)
                                    at a_ (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:49776)
                                    at ab (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:11808)
                                    at /codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16871
                                    at aw (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16908) {
                                    digest: '3984810264'
                                    }
                                    TypeError: Cannot read properties of null (reading 'useContext')
                                    at t.useContext (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:109363)
                                    at d (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/317.js:1:21495)
                                    at h (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/317.js:1:13448)
                                    at au (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:10446)
                                    at /codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:15122
                                    at aw (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16908)
                                    at a_ (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:49776)
                                    at ab (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:11808)
                                    at /codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16871
                                    at aw (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16908)
                                    Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
                                    TypeError: Cannot read properties of null (reading 'useContext')
                                    at t.useContext (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:109363)
                                    at d (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/317.js:1:21495)
                                    at h (/codebuild/output/src3157314800/src/Prod-App/.next/server/chunks/317.js:1:13448)
                                    at au (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:10446)
                                    at /codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:15122
                                    at aw (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16908)
                                    at a_ (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:49776)
                                    at ab (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:11808)
                                    at /codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16871
                                    at aw (/codebuild/output/src3157314800/src/Prod-App/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:35:16908)
.
.
.
.
.
.
.
2024-06-27T10:03:48.432Z [INFO]: ✓ Generating static pages (15/15)
2024-06-27T10:03:48.437Z [WARNING]: 
2024-06-27T10:03:48.437Z [WARNING]: > Export encountered errors on following paths:
                                    /_error: /404
                                    /_error: /500
                                    /_not-found/page: /_not-found
                                    /client-side/page: /client-side
                                    /dashboard/page: /dashboard
                                    /example/page: /example
                                    /login/page: /login
                                    /page: /
                                    /profile/page: /profile
                                    /register/page: /register
2024-06-27T10:03:48.470Z [WARNING]: error Command failed with exit code 1.
2024-06-27T10:03:48.470Z [INFO]: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
2024-06-27T10:03:48.483Z [ERROR]: !!! Build failed
2024-06-27T10:03:48.483Z [INFO]: Please read more about Amplify Hosting's support for SSR frameworks to find if your build failure is related to an unsupported feature: https://docs.aws.amazon.com/amplify/latest/userguide/amplify-ssr-framework-support.html. You may also find this troubleshooting guide useful: https://docs.aws.amazon.com/amplify/latest/userguide/troubleshooting-ssr-deployment.html
2024-06-27T10:03:48.483Z [ERROR]: !!! Error: Command failed with exit code 1
2024-06-27T10:03:48.483Z [INFO]: # Starting environment caching...
2024-06-27T10:03:48.483Z [INFO]: # Environment caching completed

Describe how you'd like this feature to work

N/A

github-actions[bot] commented 5 months ago

This has been identified as a feature request. If this feature is important to you, we strongly encourage you to give a 👍 reaction on the request. This helps us prioritize new features most important to you. Thank you!

mauerbac commented 5 months ago

Hello - thanks for reaching out! Are you able to create a support case with AWS?

mashwishi commented 5 months ago

Hello - thanks for reaching out! Are you able to create a support case with AWS?

Hi, I haven't created a support case yet as I find the dashboard console somewhat overwhelming.

I used to host react apps at vercel but vercel is expensive.

mauerbac commented 5 months ago

Sorry to hear that! Let me ask you -- what is your current issue with Amplify Hosting? Can you try to deploy your app again?

mashwishi commented 5 months ago

Sorry to hear that! Let me ask you -- what is your current issue with Amplify Hosting? Can you try to deploy your app again?

  1. It gives me errors to the pages that dont exist in the files /404 and /500
  2. Also give an error that exist only in Page directory Error: <Html> should not be imported outside of pages/_document. I am using App directory btw. I already raised the issue to next.js and they check the code is fine.
  3. Building in local, vercel and Netlify have no issues except for Amplify the log is attached above
mauerbac commented 5 months ago

What is your appID?

mashwishi commented 4 months ago

What is your appID?

That's weird, i tried it today i deleted the old deployment and created a new project and now it worked.

image

github-actions[bot] commented 4 months ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

mashwishi commented 4 months ago

@mauerbac not sure why it worked, i didnt change anything at the code but yea could be cache issue or something

github-actions[bot] commented 4 months ago

This issue has been automatically locked.