Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom build with App getInitialProps hangs #33615

Closed
kinetifex opened this issue Jan 24, 2022 · 5 comments · Fixed by #34503
Closed

Custom build with App getInitialProps hangs #33615

kinetifex opened this issue Jan 24, 2022 · 5 comments · Fixed by #34503
Labels
bug Issue was opened via the bug report template.

Comments

@kinetifex
Copy link
Contributor

Run next info (available from version 12.0.8 and up)

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64
Binaries:
  Node: 14.18.3
  npm: 6.14.15
  Yarn: 1.22.10
  pnpm: N/A
Relevant packages:
  next: 12.0.8
  react: 17.0.2
  react-dom: 17.0.2

What version of Next.js are you using?

12.0.8

What version of Node.js are you using?

14.18.3

What browser are you using?

N/A

What operating system are you using?

macOS

How are you deploying your application?

next build

Describe the Bug

We have found a bug when using Next 12 with Gasket. When the custom _app uses getInitialProps, the process hangs and never finishes.

This is reproducable with a very simple custom build script, such as in this repo.

When calling the Next build function from a script, the process hangs and never exits.

Expected Behavior

Running a build by executing the next/dist/build function from a script completes and exits successfully.

To Reproduce

Clone this repo, and run the custom build script.

git clone git@github.com:kinetifex/next-12-custom-build-bug.git
cd next-12-custom-build-bug
yarn
yarn custom-build
@kinetifex kinetifex added the bug Issue was opened via the bug report template. label Jan 24, 2022
@balazsorban44
Copy link
Member

balazsorban44 commented Jan 24, 2022

I don't think we document this being a supported use case, but the issue seems to be that you have to exit the process yourself.

const path = require("path")
const builder = require("next/dist/build").default

async function main() {
  // Do some setup, then gather some config - such as from Gasket plugins
  const config = {}
  try {
    await builder(path.resolve("."), config)
    process.exit(0)
  } catch (error) {
    console.error(error)
    process.exit(1)
  }
}

main()

should work.

@kinetifex
Copy link
Contributor Author

kinetifex commented Jan 24, 2022

This shouldn't be closed yet. We shouldn't have to exit the process manually.

My example repo has a contrived example, but with Gasket, we can perform other steps after the Next build has been completed. This has worked fine on previous versions of Next (8-11). Something introduced in Next 12 is causing this issue.

@kinetifex
Copy link
Contributor Author

And again, it only occurs with getInitialProps on the App, indicative of a bug in related code. I'll try to do some more digging, but a manual process exit is not the solution.

@balazsorban44
Copy link
Member

balazsorban44 commented Jan 25, 2022

Unless we document const builder = require("next/dist/build").default somewhere, it is not supposed to be used that way, and there is no guarantee for it to work.

What you could do instead is a script that only modifies the next.config.js file first and then runs next build the regular way node my-script && next build && node some-other-script.

kodiakhq bot pushed a commit that referenced this issue Feb 18, 2022
This fixes #33615. If an App uses `getInitialProps`, the build function never enters [this conditional block](https://github.com/vercel/next.js/blob/a52bd712fe797b59cfd05ceaa4c33096a0c346ff/packages/next/build/index.ts#L1481-L1484) and the static worker is left open.
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants