next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Pages Router + getInitialProps = Static worker unexpectedly

Open DenysMoro opened this issue 2 years ago • 10 comments

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

  • [X] 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 avatar Sep 22 '23 12:09 DenysMoro

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);

pbrissaud avatar Sep 24 '23 23:09 pbrissaud

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

> [email protected] 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

yobottehg avatar Sep 25 '23 12:09 yobottehg

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

> [email protected] 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

https://github.com/vercel/next.js/blob/ed6e8010e4a455bd90639e9d196a5d4093351b31/examples/with-sentry/pages/_error.tsx#L21-L28

longzheng avatar Sep 26 '23 11:09 longzheng

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

mick-feller avatar Oct 02 '23 20:10 mick-feller

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

evanwinter avatar Oct 04 '23 15:10 evanwinter

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:

  • Open https://github.com/oliviertassinari/next-55817
  • Run yarn && yarn build && yarn next export && npx serve out
  • v13.4.19 work OK, v13.5.1 is KO.

oliviertassinari avatar Oct 08 '23 18:10 oliviertassinari

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.

salmanorak avatar Oct 09 '23 12:10 salmanorak

Referencing here, a comment with my findings: https://github.com/vercel/next.js/discussions/48192#discussioncomment-7310817

ADTC avatar Oct 18 '23 05:10 ADTC

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

> [email protected] 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

https://github.com/vercel/next.js/blob/ed6e8010e4a455bd90639e9d196a5d4093351b31/examples/with-sentry/pages/_error.tsx#L21-L28

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 avatar Jul 02 '24 12:07 Rakhymbek

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

> [email protected] 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

> [email protected] 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?

Rakhymbek avatar Jul 02 '24 12:07 Rakhymbek