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

Stacktrace bug on dev: TypeError: The "payload" argument must be of type object. Received null #75580

Open
martinezpl opened this issue Feb 2, 2025 · 5 comments
Labels
Error Handling Related to handling errors (e.g., error.tsx, global-error.tsx). Pages Router Related to Pages Router.

Comments

@martinezpl
Copy link

martinezpl commented Feb 2, 2025

Link to the code that reproduces this issue

https://github.com/martinezpl/nextjs-stacktrace-bug-reproduction

To Reproduce

  1. npm install
  2. npx --no-install prisma generate
  3. npm run dev
  4. Trigger the handler of /api/test by sending a request

Current vs. Expected behavior

Expected behavior

The original error is raised:

        PrismaClientInitializationError: 
        Invalid `prisma.user.create()` invocation:


        error: Environment variable not found: DATABASE_URL.
        -->  schema.prisma:7
        | 
        6 |   provider = "postgresql"
        7 |   url      = env("DATABASE_URL")
        | 

        Validation Error Count: 1

Current behavior

The following error is raised and no stacktrace is provided:

[TypeError: The "payload" argument must be of type object. Received null] {
  code: 'ERR_INVALID_ARG_TYPE'
}

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:06:57 PDT 2024; root:xnu-11215.41.3~3/RELEASE_ARM64_T6041
  Available memory (MB): 24576
  Available CPU cores: 12
Binaries:
  Node: 20.18.1
  npm: 10.8.2
  Yarn: N/A
  pnpm: 9.15.1
Relevant Packages:
  next: 15.2.0-canary.33 // Latest available version is detected (15.2.0-canary.33).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.3
Next.js Config:
  output: N/A

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

Error Handling, Pages Router

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

next dev (local)

Additional context

This issue appears only on dev stage, the stacktrace is logged correctly when the error is raised in the production version.

Using Prisma as an example as this is how I encountered it and I've found others reporting this issue:
prisma/prisma#26178
Reddit Thread

But likely it is not Prisma specific.

The stack property of the raised error does lead to the original error, so the issue seems to be with the pretty printing functionality in server/patch-error-inspect

@github-actions github-actions bot added Error Handling Related to handling errors (e.g., error.tsx, global-error.tsx). Pages Router Related to Pages Router. labels Feb 2, 2025
@RoopeLehtonen
Copy link

I ran into this same error while implementing @google-cloud/logging. Downgrading to Next.js v14 removed this error, and allowed me to see the real underlying error I had. Once I fixed the underlying error, I could upgrade to Next.js v15 again. Definitely an error with Next.js. Has something to do with the Next.js printing.

@martinezpl
Copy link
Author

Another workaround is catching the badly printed error and logging its stack property:

try {
    errFoo();
} catch (e) {
    console.error(e.stack);
};

@Kianoosh76
Copy link

Happens to me as well. Downgraded to Next.js 14 and the original error was shown without any problem

@decanTyme
Copy link

Having this issue with opengraph-image and twitter-image files when embedding an image:

 GET /opengraph-image 500 in 291ms
 ⨯ [Error: TypeError: The "payload" argument must be of type object. Received null
    at cloneSourceMapV3 (node:internal/source_map/source_map:365:3)
    at new SourceMap (node:internal/source_map/source_map:145:21)
    at findSourceMap (node:internal/source_map/source_map_cache:339:17)
    at getSourcemappedFrameIfPossible (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\patch-error-inspect.js:163:90)
    at parseAndSourceMap (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\patch-error-inspect.js:265:39)
    at sourceMapError (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\patch-error-inspect.js:288:22)
    at D:\Projects\Web\portfolio.next\node_modules\next\dist\server\patch-error-inspect.js:306:30
    at AsyncLocalStorage.exit (node:async_hooks:354:14)
    at errorConstructor.<computed> (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\patch-error-inspect.js:305:67)
    at formatValue (node:internal/util/inspect:809:19)
    at formatProperty (node:internal/util/inspect:1949:11)
    at formatRaw (node:internal/util/inspect:1058:9)
    at formatValue (node:internal/util/inspect:844:10)
    at inspect (node:internal/util/inspect:368:10)
    at D:\Projects\Web\portfolio.next\node_modules\next\dist\server\patch-error-inspect.js:316:24
    at AsyncLocalStorage.exit (node:async_hooks:358:14)
    at errorConstructor.<computed> (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\patch-error-inspect.js:305:67)
    at formatValue (node:internal/util/inspect:809:19)
    at inspect (node:internal/util/inspect:368:10)
    at formatWithOptionsInternal (node:internal/util/inspect:2307:40)
    at formatWithOptions (node:internal/util/inspect:2169:10)
    at console.value (node:internal/console/constructor:350:14)
    at console.warn (node:internal/console/constructor:383:61)
    at console.error (D:\Projects\Web\portfolio.next\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:98:12057)
    at console.error (D:\Projects\Web\portfolio.next\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:106:12719)
    at console.error (D:\Projects\Web\portfolio.next\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:98:12057)
    at console.error (D:\Projects\Web\portfolio.next\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:106:12719)
    at console.error (D:\Projects\Web\portfolio.next\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:98:12057)
    at console.error (D:\Projects\Web\portfolio.next\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:106:12719)
    at console.error (D:\Projects\Web\portfolio.next\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:98:12057)
    at console.error (D:\Projects\Web\portfolio.next\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:106:12719)
    at console.error (D:\Projects\Web\portfolio.next\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:98:12057)
    at console.error (D:\Projects\Web\portfolio.next\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:106:12719)
    at console.error (D:\Projects\Web\portfolio.next\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:98:12057)
    at console.error (D:\Projects\Web\portfolio.next\node_modules\next\dist\compiled\next-server\app-page.runtime.dev.js:106:12719)
    at prefixedLog (D:\Projects\Web\portfolio.next\node_modules\next\dist\build\output\log.js:86:35)
    at Object.error (D:\Projects\Web\portfolio.next\node_modules\next\dist\build\output\log.js:100:5)
    at Object.logErrorWithOriginalStack (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\lib\router-utils\setup-dev-bundler.js:722:18)    at DevServer.logErrorWithOriginalStack (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\dev\next-dev-server.js:425:29)
    at DevServer.instrumentationOnRequestError (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\dev\next-dev-server.js:635:14)        
    at async doRender (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\base-server.js:1494:25)
    at async responseGenerator (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\base-server.js:1822:28)
    at async DevServer.renderToResponseWithComponentsImpl (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\base-server.js:1832:28)    
    at async DevServer.renderPageComponent (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\base-server.js:2259:24)
    at async DevServer.renderToResponseImpl (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\base-server.js:2297:32)
    at async DevServer.pipeImpl (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\base-server.js:959:25)
    at async NextNodeServer.handleCatchallRenderRequest (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\next-server.js:281:17)       
    at async DevServer.handleRequestImpl (D:\Projects\Web\portfolio.next\node_modules\next\dist\server\base-server.js:853:17)
    at async D:\Projects\Web\portfolio.next\node_modules\next\dist\server\dev\next-dev-server.js:371:20
    at async Span.traceAsyncFn (D:\Projects\Web\portfolio.next\node_modules\next\dist\trace\trace.js:153:20)
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues
] {
  code: 'ERR_INTERNAL_ASSERTION',
  page: '/opengraph-image'
}

Of course, removing the image fixes it.

import { ImageResponse } from "next/og"

export const alt = "About me"
export const size = {
  width: 1200,
  height: 630,
}

export const contentType = "image/png"

export default function Image() {
  return new ImageResponse(
    (
      <div>
        <img src="/logo.png" alt={alt} width={300} height={300} />
        About me
      </div>
    ),
    {
      ...size,
    },
  )
}

@KomoriDev
Copy link

Despite removing images and fonts I still get this problem.

And I am not using prisma.

 GET /api/starify?owner=KomoriDev&repo=Starify 500 in 614ms
 ✓ Compiled in 158ms (133 modules)
 ✓ Compiled in 178ms (133 modules)
 ✓ Compiled in 128ms (132 modules)
 ⨯ [TypeError: The "payload" argument must be of type object. Received null] {
  code: 'ERR_INVALID_ARG_TYPE',
  page: '/api/starify'
}

Dependencies infomation:

dependencies:
next 15.1.7
react 19.0.0
react-dom 19.0.0

devDependencies:
@types/node 20.17.19
@types/react 19.0.10
@types/react-dom 19.0.4
typescript 5.7.3
This is my entire code
/* eslint-disable @next/next/no-img-element */

import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
import { readFile } from 'node:fs/promises';

import { ImageResponse } from 'next/og'
import type { NextRequest } from 'next/server'

import GithubRepo from '@/schema'
import { formatNumber } from '@/libs'
import { Text } from '@/components/ui/text'
import { Button } from '@/components/ui/button'
import { Section } from '@/components/ui/section'
import { Sponsor, Fork, Starred } from '@/components/icons'

export const config = {
  runtime: 'node',
}

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export async function GET(req: NextRequest) {
  const { searchParams } = req.nextUrl

  const owner = searchParams.get('owner')
  const repo = searchParams.get('repo')

  if (!owner || !repo) {
    return new Response('Owner and Repo must be provided', { status: 400 })
  }

  const repoData = await GithubRepo.getRepoInfo(owner, repo)

  const BASE_WIDTH = 500
  const CHAR_WIDTH = 20
  const elementWidth = (repoData.name.length + repoData.forks.toString().length + repoData.stars.toString().length ) * CHAR_WIDTH
  const totalWidth = BASE_WIDTH + elementWidth

  return new ImageResponse(
    (
      <main
        style={{
          width: '100%',
          height: '6rem',
          padding: '0 1rem',
          display: 'flex',
          alignItems: 'center',
          justifyContent: 'space-around',
          border: 'solid #4b4b4b',
          borderWidth: 1,
          backgroundImage: 'radial-gradient(circle at 85% -10%, #263a2d 3%, #2b1e15 20%, #111111 100%)',
        }}
      >
        <Section>
          <img 
            width='28rem' 
            height='28rem' 
            src={repoData.avatar} 
            style={{'borderRadius': '0.5rem'}}
            alt='avatar'
          />
          <Text variant='title'>{repoData.name}</Text>
          <Text variant='label'>{repoData.visibility}</Text>
        </Section>

        <Section styles={{marginRight: '3rem'}}>
          <Button>
            <Sponsor />
            <Text variant='text'>Sponser</Text>
          </Button>

          <Button>
            <Fork />
            <Text variant='text'>Fork</Text>
            <Text variant='counter'>{formatNumber(repoData.forks)}</Text>
          </Button>

          <Button>
            <Starred />
            <Text variant='text'>Starred</Text>
            <Text variant='counter'>{formatNumber(repoData.stars)}</Text>
          </Button>

          {/* <img 
            width='80px'
            height='80px'
            src='#'
            alt="illustration"
            style={{
              position: 'absolute',
              bottom: '-30px',
              right: '-55px',
            }}
          />

          <img 
            width='32px'
            height='32px'
            src='#'
            alt="illustration"
            style={{
              position: 'absolute',
              bottom: '-20px',
              right: '95px',
            }}
          />

          <img 
            width='50px'
            height='24px'
            src='#'
            alt="illustration"
            style={{
              position: 'absolute',
              bottom: '28px',
              right: '125px',
            }}
          /> */}
        </Section>
      </main>
    ),
    {
      width: totalWidth,
      height: 96,
      // fonts: [
      //   {
      //     name: 'OpenSans',
      //     data: await readFile(join(__dirname, '../../../assets/fonts/OpenSans-SemiBold.ttf')),
      //     weight: 600,
      //     style: 'normal',
      //   },
      // ],
    }
  )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Handling Related to handling errors (e.g., error.tsx, global-error.tsx). Pages Router Related to Pages Router.
Projects
None yet
Development

No branches or pull requests

5 participants