vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.43k stars 26.79k forks source link

Pages Router + getInitialProps = Static worker unexpectedly #55817

Open DenysMoro opened 1 year ago

DenysMoro commented 1 year ago

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

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

pbrissaud commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

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

mick-feller commented 1 year ago

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

evanwinter commented 12 months ago

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

oliviertassinari commented 11 months ago

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 commented 11 months ago

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:

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

ADTC commented 11 months ago

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

Rakhymbek commented 3 months ago

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

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 commented 3 months ago

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?