Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Temporary disable Next.js pages on build

There are SSR-related problems with several pages in Next.js project that results in errors on npm run build and prevent the project from being built:

pages/
  foo/
    bar/
      [id].jsx
      index.jsx
    index.jsx
  ...

For example, bar:

export function getStaticProps() {
  return someApiCallThatCurrentlyFails()
  ...
}

export default function Bar() {...}

As a quick fix, it may be convenient to just not build bar/*.* pages and make routes unavailable.

Can pages be ignored on Next.js build without physically changing or removing page component files in the project?

like image 916
Estus Flask Avatar asked Mar 30 '21 14:03

Estus Flask


People also ask

What is SSR in NextJS?

Next Js is a React-based framework that provides a developer with everything required for a production-grade application. SSR or Server Side Rendering is also known as dynamic rendering. In SSR the page is generated each time the server gets a request.

What is NextPage in NextJS?

NextPage is a type exported by NextJS. When we write Page: NextPage we're saying that our Page component is of type NextPage . Follow this answer to receive notifications.


1 Answers

You can configure the pageExtensions in the next.config.js.

// next.config.js
module.exports = {
  pageExtensions: ["page.js"],
}

After configuring this, the only pages with *.page.js will be considered in the below given directory structure.

pages/
├── user
│   └── setting
│       ├── index.js
├── _app.page.js
├── _document.page.js
├── list.page.js
└── theme.ts

Custom file ignores patterns that are not supported yet. You can visit the PR created here, and the solution given here. This is the most satisfactory solution so far.

like image 173
Kiran Maniya Avatar answered Oct 27 '22 00:10

Kiran Maniya