next-auth: defaultCookies is not defined

Question 💬

Hi I’m using next-auth version: 3.27.3 I suddenly got this error while running my app. Anyone encountered this? Thank you.

error - unhandledRejection: ReferenceError: defaultCookies is not defined
    at C:\Users\MAGICSOFT Mike\Desktop\NEW MAGICSOFT\crd-prototype\node_modules\next-auth\dist\server\index.js:102:9
    at new Promise (<anonymous>)
    at NextAuthHandler (C:\Users\MAGICSOFT Mike\Desktop\NEW MAGICSOFT\crd-prototype\node_modules\next-auth\dist\server\index.js:67:10)
    at NextAuth (C:\Users\MAGICSOFT Mike\Desktop\NEW MAGICSOFT\crd-prototype\node_modules\next-auth\dist\server\index.js:299:10)
    at __WEBPACK_DEFAULT_EXPORT__ (C:\Users\MAGICSOFT Mike\Desktop\NEW MAGICSOFT\crd-prototype\.next\server\pages\api\auth\[...nextauth].js:188:128)
    at Object.apiResolver (C:\Users\MAGICSOFT Mike\Desktop\NEW MAGICSOFT\crd-prototype\node_modules\next\dist\server\api-utils.js:101:15)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async DevServer.handleApiRequest (C:\Users\MAGICSOFT Mike\Desktop\NEW MAGICSOFT\crd-prototype\node_modules\next\dist\server\next-server.js:775:9)
    at async Object.fn (C:\Users\MAGICSOFT Mike\Desktop\NEW MAGICSOFT\crd-prototype\node_modules\next\dist\server\next-server.js:666:37)

How to reproduce ☕️

npm run dev

Contributing 🙌🏽

No, I am afraid I cannot help regarding this

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 16 (3 by maintainers)

Most upvoted comments

Hi, v3 is an unmaintained version. Please upgrade to v4 and report back if you still experience the issue.

Same error here, nothing changed on the codebase (and using older v3), my client just did another deploy due to CMS updates. This is unacceptable.

[POST] /api/auth/_log
20:14:15:50
2022-06-14T18:14:18.805Z	8563085b-526b-4d39-bb06-b37d643e1344	ERROR	Unhandled Promise Rejection 	{"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"ReferenceError: defaultCookies is not defined","reason":{"errorType":"ReferenceError","errorMessage":"defaultCookies is not defined","stack":["ReferenceError: defaultCookies is not defined","    at /var/task/node_modules/next-auth/dist/server/index.js:102:9","    at new Promise (<anonymous>)","    at NextAuthHandler (/var/task/node_modules/next-auth/dist/server/index.js:67:10)","    at NextAuth (/var/task/node_modules/next-auth/dist/server/index.js:299:10)","    at /var/task/.next/server/chunks/5599.js:546:64","    at Object.apiResolver (/var/task/node_modules/next/dist/server/api-utils/node.js:185:15)","    at processTicksAndRejections (internal/process/task_queues.js:95:5)","    at async NextNodeServer.runApi (/var/task/node_modules/next/dist/server/next-server.js:395:9)","    at async Object.fn (/var/task/node_modules/next/dist/server/base-server.js:496:37)","    at async Router.execute (/var/task/node_modules/next/dist/server/router.js:226:36)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: ReferenceError: defaultCookies is not defined","    at process.<anonymous> (/var/runtime/index.js:35:15)","    at process.emit (events.js:412:35)","    at processPromiseRejections (internal/process/promises.js:245:33)","    at processTicksAndRejections (internal/process/task_queues.js:96:32)"]}
Unknown application error occurred

EDIT I downgraded next-auth explicitly to version 3.29.3 (was ^3.29.3 before) and now it works!

I’ll have a look, thanks… Note that v3 has been unmaintained for a while now, even the security advisory points out that you should upgrade to v4, at some point (probably soon) we will stop patching v3.

This is broken for me also in 4.5.0

If the issue happens in v4, that will be priority. cc @ThangHuuVu

3.29.6 should include this fix: https://github.com/nextauthjs/next-auth/pull/4711, still unable to reproduce anything similar in v4.

@balazsorban44 This is still broken and now the patch version for CVE-2022-31093 also includes this error. There is currently no way for anyone on v3 to avoid this vulnerability. This commenter has pinpointed the error so I think this should be addressed: https://github.com/nextauthjs/next-auth/commit/87f6f576b1f31249868991a2d1fecc4a9e4f5ce8#r75837858

I’ve just got the same problem, can’t upgrade because I’m using the firebase adapter. Downgrading to 3.29.3 works. Thanks, fabien!

Upgrading from 3.27.3 to 3.29.3 works for me too . Thanks!

I also get an error like that, even though previously the application was running fine.

image