Skip to content

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?

Answer

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.