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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
edgarlcs opened this issue Nov 6, 2022 · 17 comments 路 Fixed by #5745
Closed

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

edgarlcs opened this issue Nov 6, 2022 · 17 comments 路 Fixed by #5745
Labels
bug Something isn't working priority Priority fix or enhancement

Comments

@edgarlcs
Copy link

edgarlcs commented Nov 6, 2022

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. (/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

@edgarlcs edgarlcs added the question Ask how to do something or how something works label Nov 6, 2022
@Supergamer1337
Copy link

I'm getting the exact same error, but while trying to implement the Credentials provider.

@Supergamer1337
Copy link

I fixed it by going back to V4.15.1

@edgarlcs
Copy link
Author

edgarlcs commented Nov 6, 2022

I fixed it by going back to V4.15.1

All right that fixed that issue but now I am getting:
Error: This action with HTTP GET is not supported by NextAuth.js when trying to get in, any idea on that? what is going on haha

@FilipSzutkowski
Copy link

Getting the same error both when passing providers and when the providers array is empty.

@FilipSzutkowski
Copy link

@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'.

@ThangHuuVu ThangHuuVu added bug Something isn't working and removed question Ask how to do something or how something works labels Nov 6, 2022
@ThangHuuVu
Copy link
Member

ThangHuuVu commented Nov 6, 2022

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

@trungthecelestial
Copy link

same problem with me

@tortechnocom
Copy link

Same problem stuck with "error - Error: Cannot find module 'next/headers'"

@smolak
Copy link

smolak commented Nov 6, 2022

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

Shouldn't it be a breaking change then, and so v5? Looks that way. The fact it might not work for Next 13 (fair enough, experimental) shouldn't mean it should be the same for Next 12.x.

@balazsorban44
Copy link
Member

Sorry for the inconvenience, a patch is coming, you can test it out with #5745 (comment) please report back if it worked for you! 馃檹 I plan to release this very 馃敎

@Getitdan
Copy link

Getitdan commented Nov 6, 2022

TL;DR

  1. Edit package.json to:
    "next-auth": "4.15.1"
  2. Make a reminder to review this issue, and revert when solved.

@balazsorban44
Copy link
Member

Should be fixed in 4.16.3

@timalive
Copy link

I am still getting this error on 4.15.1 and 4.16.3

@tzachbon
Copy link

I'm getting this on 4.18.6

@dominik-myszkowski
Copy link

4.18.7 and still the same error... What is going on???

@B3none
Copy link

B3none commented Jan 26, 2023

4.18.7 and still the same error... What is going on???

If you get this whilst NOT on the sign in page

I got this error on 4.18.10 when trying to use unstable_getServerSession without passing the correct arguments. If you pass those it'll work.

@balazsorban44
Copy link
Member

balazsorban44 commented Jan 30, 2023

Please don't comment on already closed issues, they are not monitored. You can add your reproduction at #6559

Read #6559 (comment) first. As #5743 (comment) pointed out, you might have misconfigured unstable_getServerSession

@nextauthjs nextauthjs locked as resolved and limited conversation to collaborators Jan 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working priority Priority fix or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.