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

Error: The initialHeaders argument for Prerender must be an object with string key/values #49374

Closed
1 task done
ivodevbr opened this issue May 6, 2023 · 2 comments · Fixed by #49643
Closed
1 task done
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template.

Comments

@ivodevbr
Copy link

ivodevbr commented May 6, 2023

Verify canary release

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

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #42~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 18 17:40:00 UTC 2
    Binaries:
      Node: 18.15.0
      npm: 9.5.0
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.4.1
      eslint-config-next: 13.4.1
      react: 18.2.0
      react-dom: 18.2.0

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

Middleware / Edge (API routes, runtime)

Link to the code that reproduces this issue

npx create-next-app@latest // with typescript, eslint, tailwind src directory and @/* import,

To Reproduce

// latest version from 2023-may-06
  "dependencies": {
    "@types/node": "20.1.0", "@types/react": "18.2.6", "@types/react-dom": "18.2.4","autoprefixer": "10.4.14",
    "eslint": "8.40.0", "eslint-config-next": "13.4.1", "next": "13.4.1",
    "postcss": "8.4.23", "react": "18.2.0", "react-dom": "18.2.0", 
    "tailwindcss": "3.3.2", "typescript": "5.0.4"
  }
// project/src/app/example/cookie1/route.ts
import { NextResponse } from "next/server";

export async function GET(req: NextRequest) {
  const res = new NextResponse();
  res.cookies.set("theme", "light");
  res.cookies.set("my_company", "ACME");
  return res;
};

Describe the Bug

if you run

rm -rf .next && npm run build && npm run start

Its run ok, but if you deploy it at vercel you get this error.
Error: The initialHeaders argument for Prerender must be an object with string key/values

Maybe source of problem is this code:

https://github.com/vercel/vercel/blob/main/packages/build-utils/src/prerender.ts

// line 96
    if (initialHeaders !== undefined) {
      if (
        !initialHeaders ||
        typeof initialHeaders !== 'object' ||
        Object.entries(initialHeaders).some(
          ([key, value]) => typeof key !== 'string' || typeof value !== 'string'
        )
      ) {
        throw new Error(
          `The \`initialHeaders\` argument for \`Prerender\` must be an object with string key/values`
        );
      }
      this.initialHeaders = initialHeaders;
    }

Expected Behavior

It deploys with out error.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Vercel

@ivodevbr ivodevbr added the bug Issue was opened via the bug report template. label May 6, 2023
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label May 6, 2023
@ivodevbr
Copy link
Author

ivodevbr commented May 6, 2023

Documentation about cookie in route.
https://nextjs.org/docs/app/api-reference/functions/next-response#setname-value

@ijjk ijjk added area: app App directory (appDir: true) and removed Runtime Related to Node.js or Edge Runtime with Next.js. labels May 10, 2023
ijjk added a commit that referenced this issue May 11, 2023
This makes sure we have the initial headers in the correct shape during
build.

Fixes: #49374
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@ivodevbr @ijjk and others