next-auth: Getting "Error: Cannot find module 'next/headers'" when accessing "api/auth/signin"

Question 💬

Hello I am trying to implement Facebook Login but I am getting this error:

`error - Error: Cannot find module ‘next/headers’ Require stack:

  • /Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next-auth/next/index.js
  • /Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next-auth/index.js
  • /Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/.next/server/pages/api/auth/[…nextauth].js
  • /Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next/dist/server/next-server.js
  • /Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next/dist/server/next.js
  • /Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next/dist/server/lib/start-server.js
  • /Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next/dist/cli/next-dev.js
  • /Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next/dist/lib/commands.js
  • /Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next/dist/bin/next at Function.Module._resolveFilename (node:internal/modules/cjs/loader:956:15) at Function.mod._resolveFilename (/Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next/dist/build/webpack/require-hook.js:27:32) at Function.mod._resolveFilename (/Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next/dist/build/webpack/require-hook.js:27:32) at Function.mod._resolveFilename (/Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next/dist/build/webpack/require-hook.js:27:32) at Function.Module._load (node:internal/modules/cjs/loader:804:27) at Module.require (node:internal/modules/cjs/loader:1028:19) at require (node:internal/modules/cjs/helpers:102:18) at Object.<anonymous> (/Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next-auth/next/index.js:15:16) at Module._compile (node:internal/modules/cjs/loader:1126:14) at Object.Module._extensions…js (node:internal/modules/cjs/loader:1180:10) { code: ‘MODULE_NOT_FOUND’, requireStack: [ ‘/Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next-auth/next/index.js’, ‘/Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next-auth/index.js’, ‘/Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/.next/server/pages/api/auth/[…nextauth].js’, ‘/Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next/dist/server/next-server.js’, ‘/Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next/dist/server/next.js’, ‘/Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next/dist/server/lib/start-server.js’, ‘/Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next/dist/cli/next-dev.js’, ‘/Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next/dist/lib/commands.js’, ‘/Users/edgarlcs/Documents/GitHub/rifadisimo/rifadisimo/node_modules/next/dist/bin/next’ ] }`

How to reproduce ☕️

Here is the code if you want to try by yourself https://github.com/edgarlcs/rifadisimo

Contributing 🙌🏽

No, I am afraid I cannot help regarding this

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 17 (4 by maintainers)

Most upvoted comments

Sorry for the inconvenience, a patch is coming, you can test it out with https://github.com/nextauthjs/next-auth/pull/5745#issuecomment-1304859690 please report back if it worked for you! 🙏 I plan to release this very 🔜

For now, next@12 users should stay at v4.15.x until we fix this issue for v4.16.x which is intended for next@13 users. The root cause is that in v4.16.x we use next/headers package from next@13 to support getting the session in React Server Components. More in this PR

I am still getting this error on 4.15.1 and 4.16.3

@Supergamer1337 @edgarlcs seems like Next-Auth requires Next.js version 13. Updating Next fixed the problem for me on the newest version of Next-Auth.

Really weird that it didn’t say anything about Next version upon ‘npm install’.

I fixed it by going back to V4.15.1