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

Pages Router + getInitialProps = Static worker unexpectedly #55817

Open
1 task done
DenysMoro opened this issue Sep 22, 2023 · 10 comments
Open
1 task done

Pages Router + getInitialProps = Static worker unexpectedly #55817

DenysMoro opened this issue Sep 22, 2023 · 10 comments
Labels
bug Issue was opened via the bug report template.

Comments

@DenysMoro
Copy link

Link to the code that reproduces this issue

https://github.com/ifier/next-js-SIGINT

To Reproduce

  1. Don't start app
  2. Run npm run build
  3. See list of errors
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
...

If you will go to _app and comment out getInitialProps section fully - it will build with no errors.

Current vs. Expected behavior

I would expect not to see this list

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 21.6.0: Sat Jun 18 17:07:25 PDT 2022; root:xnu-8020.140.41~1/RELEASE_X86_64
    Binaries:
      Node: 16.14.0
      npm: 8.3.1
      Yarn: 1.22.19
      pnpm: N/A
    Relevant Packages:
      next: 13.5.2
      eslint-config-next: 13.5.2
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.2.2
    Next.js Config:
      output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Additional context

No response

@DenysMoro DenysMoro added the bug Issue was opened via the bug report template. label Sep 22, 2023
@pbrissaud
Copy link

Same error after upgrade Next.js from v13.4.19 to v13.5.2and using a trpc backend :

function App({ Component, pageProps }: AppProps) {
  return (
    <>
      <style jsx global>
        {`
          :root {
            --lora-font: ${lora.style.fontFamily};
          }
        `}
      </style>
      <ThemeProvider attribute="class">
        <UserProvider>
          <Toaster />
          <Component {...pageProps} />
        </UserProvider>
      </ThemeProvider>
      <ReactQueryDevtools initialIsOpen={false} />
      <Script
        src={`https://maps.googleapis.com/maps/api/js?key=${process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY}&libraries=places&callback=Function.prototype`}
      />
    </>
  );
}

export default trpc.withTRPC(App);

@yobottehg
Copy link

yobottehg commented Sep 25, 2023

Same here but without getInitialProps in_app.tsx but with initialProps related code in _error.tsx:

Pages router and SSR only (ServerSideProps everywhere)

Error.getInitialProps = ({ res, err }: NextPageContext) => {
  const statusCode = res ? res.statusCode : err ? err.statusCode : 404
  return { statusCode }
}

export default Error
 npm run build

> ksb-website@1.0.0 build
> NODE_ENV=production next build

   Skipping validation of types
   Skipping linting
 ✓ Creating an optimized production build   
 ✓ Compiled successfully
 ✓ Collecting page data   
 ✓ Finalizing page optimization   

Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT

Removing Error.getInitialProps removes the error.

This is 100% from the docs:
https://nextjs.org/docs/pages/building-your-application/routing/custom-error#more-advanced-error-page-customizing

@longzheng
Copy link
Contributor

longzheng commented Sep 26, 2023

Same here but without getInitialProps in_app.tsx but with initialProps related code in _error.tsx:

Pages router and SSR only (ServerSideProps everywhere)

Error.getInitialProps = ({ res, err }: NextPageContext) => {
  const statusCode = res ? res.statusCode : err ? err.statusCode : 404
  return { statusCode }
}

export default Error
 npm run build

> ksb-website@1.0.0 build
> NODE_ENV=production next build

   Skipping validation of types
   Skipping linting
 ✓ Creating an optimized production build   
 ✓ Compiled successfully
 ✓ Collecting page data   
 ✓ Finalizing page optimization   

Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT

Removing Error.getInitialProps removes the error.

This is 100% from the docs: https://nextjs.org/docs/pages/building-your-application/routing/custom-error#more-advanced-error-page-customizing

Good find. I'm also running this on a project that uses a custom getInitialProps for Sentry error reporting as recommended by Next.js' example code and documentation

CustomErrorComponent.getInitialProps = async (contextData) => {
// In case this is running in a serverless function, await this in order to give Sentry
// time to send the error before the lambda exits
await Sentry.captureUnderscoreErrorException(contextData)
// This will contain the status code of the response
return NextErrorComponent.getInitialProps(contextData)
}

@mick-feller
Copy link

i have the same issue, seems to be introduced in 13.5, 13.4 seems to be working fine for me.

@evanwinter
Copy link
Contributor

I am seeing this is 13.4.12, so not sure if 13.5 is the only culprit

@oliviertassinari
Copy link
Contributor

oliviertassinari commented Oct 8, 2023

Same error after upgrade Next.js from v13.4.19 to v13.5.2

I have also noticed how all the content of the <Head> element used in a page is no longer in the static export. e.g.

yarn build && yarn next export && npx serve out
import Head from 'next/head'
import { Inter } from 'next/font/google'
import styles from '@/styles/Home.module.css'

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

export default function Home() {
  return (
    <>
      <Head>
        <title>Create Next App</title>
        <meta name="description" content="Generated by create next app" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <link rel="icon" href="/favicon.ico" />
      </Head>

Gone

Screenshot 2023-10-08 at 20 07 05

If I do:

diff --git a/src/pages/index.tsx b/src/pages/index.tsx
index 27c489b..b98b0c1 100644
--- a/src/pages/index.tsx
+++ b/src/pages/index.tsx
     </>
   )
 }
+
+Home.getInitialProps = () => ({});

A reproduction:

@salmanorak
Copy link

salmanorak commented Oct 9, 2023

I have gone through a couple of versions. I have run the build with all the below versions.
The first version that doesn't throw errors is 13.3.4. All version I have tried above 13.3.4 was throwing SIGINT or SIGTERM error on the build logs.

Version tried:

  • 13.4.0
  • 13.4.19
  • 13.5.2
  • 13.5.3
  • 13.5.4

I want to share these results in case it can be helpful.

@ADTC
Copy link
Contributor

ADTC commented Oct 18, 2023

Referencing here, a comment with my findings: #48192 (reply in thread)

@Rakhymbek
Copy link

Rakhymbek commented Jul 2, 2024

Same here but without getInitialProps in_app.tsx but with initialProps related code in _error.tsx:
Pages router and SSR only (ServerSideProps everywhere)

Error.getInitialProps = ({ res, err }: NextPageContext) => {
  const statusCode = res ? res.statusCode : err ? err.statusCode : 404
  return { statusCode }
}

export default Error
 npm run build

> ksb-website@1.0.0 build
> NODE_ENV=production next build

   Skipping validation of types
   Skipping linting
 ✓ Creating an optimized production build   
 ✓ Compiled successfully
 ✓ Collecting page data   
 ✓ Finalizing page optimization   

Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT

Removing Error.getInitialProps removes the error.
This is 100% from the docs: https://nextjs.org/docs/pages/building-your-application/routing/custom-error#more-advanced-error-page-customizing

Good find. I'm also running this on a project that uses a custom getInitialProps for Sentry error reporting as recommended by Next.js' example code and documentation

CustomErrorComponent.getInitialProps = async (contextData) => {
// In case this is running in a serverless function, await this in order to give Sentry
// time to send the error before the lambda exits
await Sentry.captureUnderscoreErrorException(contextData)
// This will contain the status code of the response
return NextErrorComponent.getInitialProps(contextData)
}

Did you solve it by removing CustomErrorComponent.getInitialProps?
I have the same configuration in _error.tsx from Sentry cli.
What did you do exactly?

@Rakhymbek
Copy link

Same here but without getInitialProps in_app.tsx but with initialProps related code in _error.tsx:

Pages router and SSR only (ServerSideProps everywhere)

Error.getInitialProps = ({ res, err }: NextPageContext) => {
  const statusCode = res ? res.statusCode : err ? err.statusCode : 404
  return { statusCode }
}

export default Error
 npm run build

> ksb-website@1.0.0 build
> NODE_ENV=production next build

   Skipping validation of types
   Skipping linting
 ✓ Creating an optimized production build   
 ✓ Compiled successfully
 ✓ Collecting page data   
 ✓ Finalizing page optimization   

Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT

Removing Error.getInitialProps removes the error.

This is 100% from the docs: https://nextjs.org/docs/pages/building-your-application/routing/custom-error#more-advanced-error-page-customizing

Same here but without getInitialProps in_app.tsx but with initialProps related code in _error.tsx:

Pages router and SSR only (ServerSideProps everywhere)

Error.getInitialProps = ({ res, err }: NextPageContext) => {
  const statusCode = res ? res.statusCode : err ? err.statusCode : 404
  return { statusCode }
}

export default Error
 npm run build

> ksb-website@1.0.0 build
> NODE_ENV=production next build

   Skipping validation of types
   Skipping linting
 ✓ Creating an optimized production build   
 ✓ Compiled successfully
 ✓ Collecting page data   
 ✓ Finalizing page optimization   

Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT
Static worker unexpectedly exited with code: null and signal: SIGINT

Removing Error.getInitialProps removes the error.

This is 100% from the docs: https://nextjs.org/docs/pages/building-your-application/routing/custom-error#more-advanced-error-page-customizing

You've just removed Error. getInitialProps, but did you add something to replace it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

10 participants