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

undefined reading headers using next/headers && appDir

Open caiocinel opened this issue 3 years ago • 1 comments

Verify canary release

  • [X] 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: 18.8.0 npm: N/A Yarn: N/A pnpm: N/A Relevant packages: next: 13.0.3-canary.0 eslint-config-next: 13.0.0 react: 18.2.0 react-dom: 18.2.0

What browser are you using? (if relevant)

Chrome 107

How are you deploying your application? (if relevant)

npm run dev

Describe the Bug

When tries get headers from page using appDir, i get Error: Cannot read properties of undefined (reading 'headers'),

Expected Behavior

Get request headers

Link to reproduction

https://stackblitz.com/edit/vercel-next-js-ee8sib?file=app%2Fpage.tsx

To Reproduce

Just import headers then call function on function body

import { headers } from 'next/headers' export default async function Home() { const cookie = headers().get('cookie'); }

caiocinel avatar Nov 07 '22 02:11 caiocinel

Can you reproduce this locally as well, or only on StackBlitz? It works fine on my local machine but reproduces on your link. :thinking:

balazsorban44 avatar Nov 08 '22 07:11 balazsorban44

Can you reproduce this locally as well, or only on StackBlitz? It works fine on my local machine but reproduces on your link. 🤔

Also in my machine, i've tried with most recent versions (v13.0.6 and 13.0.7-canary.1) and problem continues

The "cookies()" function of next/headers also has the same problem, not being an alternative.

caiocinel avatar Dec 04 '22 22:12 caiocinel

Fixed uninstalling node 18 and reinstalling v19

caiocinel avatar Dec 07 '22 01:12 caiocinel

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[bot] avatar Jan 06 '23 12:01 github-actions[bot]