添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

While prerendering a page during next build , an error occurred. This can happen for various reasons, including:

  • Incorrect file structure or non-page files in the pages/ directory
  • Expecting props to be populated which are not available during prerendering
  • Using browser-only APIs in components without proper checks
  • Incorrect configuration in getStaticProps or getStaticPaths
  • Possible Ways to Fix It

    In the Pages Router, only special files are allowed to generate pages. You cannot colocate other files (e.g., components, styles) within the pages directory.

    Correct structure:

    pages/
    ├── index.js
    └── about.js
    components/
    └── Header.js
    styles/
    └── globals.css
    

    App Router (Next.js 13+)

    The App Router allows colocation of pages and other files in the same folder. This provides a more intuitive project structure.

    Example folder structure:

    ├── layout.tsx ├── page.tsx ├── about/ │ └── page.tsx └── blog/ ├── page.tsx └── PostCard.tsx

    2. Handle undefined props and missing data

    For the Pages Router, use conditional checks and return appropriate props or a 404 page: