Closed himadrinath closed 5 years ago
Is the error happening in the browser or in the node js side? Also, is it when you're just running the site regularly, or is it during a static export?
@nfriedly in browser side. just running the site during routing
Can you try with next-cookies@1.1.0 and @1.0.4, and let me know if it works with either of those versions?
npm i next-cookies@1.1.0 --save-exact
npm i next-cookies@1.0.4 --save-exact
@nfriedly ok
@nfriedly 1.1.0 working. not tested 1.0.4
Okay, cool, that's a good short-term solution. I'll try and figure out what happened with 1.1.1.
Thanks
Sorry about that, we really need to get some tests going for this repo.
I'm a little confused though because it seems like the culprit is on the server-side:
https://github.com/matthewmueller/next-cookies/blob/master/next-cookies.node.js#L18
Can you check if this works?
if (!ctx.req || !ctx.req.headers) return {}
EDIT: Is the !ctx.req.headers
conditional in your getInitialProps code?
I think something is causing the client to run the server code.
I agree about needing tests. I used nightwatch once before and I think it might be part of the answer here.
Here's the issue: #14 moved the browser code to the dist/
folder, but also added it to .gitignore
. Because there's no .npmignore
file, npm defaults to ignoring the items listed in the .gitignore
file. So, the minified browser code didn't get published to npm.
Without the specified browser code available, webpack is falling back to the server code which, of course, doesn't work in the browser.
I just published a v1.1.2 that should address this. @himadrinath can you test it out and confirm?
npm i next-cookies@1.1.2 --save
ok
@nfriedly its working. thanks
Perfect! Thank you for confirming, and sorry for the trouble.
Hey this is still happening I can't read cookies in getInitialProps
Still happening on my end
Happening for me as well
For me too
@nfriedly any ideas?
In my case, problem was I tried to use it in a HOC wraping around next _app.js
...
I have not digged how next works internally, but at this stage it seems ctx
is not the same, and ctx.req
is undefined
.
Using last version of next-cookies
in deeper components/HOC (like using it on any normal page in pages
folder) works like a charm.
@matthewmueller eveything working fine until i update to nextjs 8.0.3 (next-cookies 1.1.1)
same code working before but now getting this on the client side
Error in error page
getInitialProps
: TypeError: Cannot read property 'headers' of undefinedif (!ctx.req.headers) return {}; // for Static export feature of Next.js
pointing this line in next-cookies.node.js