next.js: Error: invariant: Expected pageData to be a string for app data request but received undefined. This is a bug in Next.js.

Verify canary release

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

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 16.19.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 13.2.4
      eslint-config-next: 13.0.0
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Data fetching (gS(S)P, getInitialProps), Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue

I cannot reproduce it locally.

To Reproduce

I don’t know exactly how to reproduce it locally, it seems to happen only when deployed on Vercel.

Describe the Bug

When executing a serverless function, I am getting the error Error: invariant: Expected pageData to be a string for app data request but received undefined. This is a bug in Next.js. approximately 50% of the times. This error seems to happen only when deployed on vercel. I see the error just by checking the logs. It seems a bug in the cachedData, since this code is what is giving this error: https://github.com/vercel/next.js/pull/46204/files

Here is the Serverless execution success and fail chart by day, almost 50% fails due to this error. image

Here is a full error example found in the “Logs”:

2023-04-01T22:34:02.255Z	undefined	INFO	info  - Loaded env from /var/task/.env.production
Error: invariant: Expected pageData to be a string for app data request but received undefined. This is a bug in Next.js.
    at NextNodeServer.renderToResponseWithComponentsImpl (/var/task/node_modules/next/dist/server/base-server.js:1013:27)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async NextNodeServer.renderPageComponent (/var/task/node_modules/next/dist/server/base-server.js:1072:24)
    at async NextNodeServer.renderToResponseImpl (/var/task/node_modules/next/dist/server/base-server.js:1098:32) {
  page: '/front-end-jobs-in-antwerp'
}
RequestId: 3193f9ce-3d2b-493d-b5f4-6d8c4c407b22 Error: Runtime exited with error: exit status 1
Runtime.ExitError

Expected Behavior

I expect the cache to work as expected and to have no errors in the serveless function executions. My external backend service , where the serverless function gets the data, does not fail, so the expected behaviour is that the serveless function gets the data and cache it as expected.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-1391

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 11
  • Comments: 23 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Can anyone reporting this is still occurring provide a deployment or repo with reproduction where they are seeing it?

The confirmed cases of this have all been resolved and are working properly in the latest version of Next.js

This is happening for me on v13.4.7

Same, still happening with v13.4.6.

I think we should re-open the issue.

Hi there, I’m still seeing these error logs in production using v13.4.6

Error: invariant: Expected pageData to be a string for app data request but received undefined. This is a bug in Next.js. at NextNodeServer.renderToResponseWithComponentsImpl (/var/task/node_modules/next/dist/server/base-server.js:1274:27) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async NextNodeServer.renderPageComponent (/var/task/node_modules/next/dist/server/base-server.js:1333:24) at async NextNodeServer.renderToResponseImpl (/var/task/node_modules/next/dist/server/base-server.js:1365:32) at async NextNodeServer.pipeImpl (/var/task/node_modules/next/dist/server/base-server.js:641:25) at async Object.fn (/var/task/node_modules/next/dist/server/next-server.js:1139:21) at async Router.execute (/var/task/node_modules/next/dist/server/router.js:315:32) at async NextNodeServer.runImpl (/var/task/node_modules/next/dist/server/base-server.js:615:29) at async NextNodeServer.handleRequestImpl (/var/task/node_modules/next/dist/server/base-server.js:546:20) { page: ‘/categorias/lamparas’ } RequestId: 065834d7-2433-4378-8637-e8b243f845c2 Error: Runtime exited with error: exit status 1 Runtime.ExitError

Anyone else?

@ijjk still happening with Next.js v13.4.4

Seeing the same issue, specifically for Google web crawling.

TYPE: Serverless Function

Error: invariant: Expected pageData to be a string for app data request but received undefined. This is a bug in Next.js.
    at NextNodeServer.renderToResponseWithComponentsImpl (/var/task/node_modules/next/dist/server/base-server.js:1013:27)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async NextNodeServer.renderPageComponent (/var/task/node_modules/next/dist/server/base-server.js:1072:24)
    at async NextNodeServer.renderToResponseImpl (/var/task/node_modules/next/dist/server/base-server.js:1098:32) {
  page: 'X'
}
RequestId: X Error: Runtime exited with error: exit status 1
Runtime.ExitError