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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NextAuth v5 TypeError: next_dist_server_web_exports_next_request__WEBPACK_IMPORTED_MODULE_0__ is not a constructor #9922

Closed
chungweileong94 opened this issue Feb 6, 2024 · 18 comments
Labels
bug Something isn't working upstream The issue dervies from one of next-auth dependencies

Comments

@chungweileong94
Copy link
Contributor

Environment

System:
    OS: macOS 14.3
    CPU: (8) arm64 Apple M2
    Memory: 2.59 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
Binaries:
    Node: 18.19.0 - ~/Library/Caches/fnm_multishells/18527_1707202116497/bin/node
    Yarn: 1.22.21 - ~/Library/Caches/fnm_multishells/18527_1707202116497/bin/yarn
    npm: 10.2.3 - ~/Library/Caches/fnm_multishells/18527_1707202116497/bin/npm
    pnpm: 8.14.1 - ~/Library/Caches/fnm_multishells/18527_1707202116497/bin/pnpm
    bun: 1.0.26 - /opt/homebrew/bin/bun
Browsers:
    Safari: 17.3
npmPackages:
    next: 14.0.4 => 14.0.4 
    next-auth: 5.0.0-beta.8 => 5.0.0-beta.8 
    react: ^18 => 18.2.0

Reproduction URL

https://github.com/chungweileong94/nextauth-route-handler-error

Describe the issue

If one of the AUTH_URL and NEXTAUTH_URL is set, we will get the following error.

TypeError: next_dist_server_web_exports_next_request__WEBPACK_IMPORTED_MODULE_0__ is not a constructor

How to reproduce

  1. Clone the repro
  2. Run the app via pnpm dev
  3. Navigate to http://localhost:3000/api/auth/signin

Expected behavior

It should show the next-auth built-in sign-in page. Instead, it shows throw 500 error (TypeError: next_dist_server_web_exports_next_request__WEBPACK_IMPORTED_MODULE_0__ is not a constructor)

@chungweileong94 chungweileong94 added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Feb 6, 2024
@chungweileong94
Copy link
Contributor Author

The problem seems to be caused by new NextRequest(...) in reqWithEnvURL

return new NextRequest(href.replace(origin, envOrigin), req)

Which is why setting either AUTH_URL or NEXTAUTH_URL will bypass the problem.

@Talent30

This comment was marked as off-topic.

@balazsorban44
Copy link
Member

balazsorban44 commented Feb 6, 2024

Related to #9795. This sounds like an upstream Next.js bug which I thought has been fixed. Will have a look there. The workaround is to patch new NextRequest to new NextRequest.default for now, or drop the env variables.

Note: You most likely don't need AUTH_URL or NEXTAUTH_URL anyway, it's not been required for a very long time, unless you want a custom path for your auth route, or behind a proxy.

@balazsorban44 balazsorban44 added upstream The issue dervies from one of next-auth dependencies and removed triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Feb 6, 2024
@chungweileong94
Copy link
Contributor Author

Note: You most likely don't need AUTH_URL or NEXTAUTH_URL, it's not been required for a very long time, unless you want a custom path for your auth route, or behind a proxy.

Ah, good to know.

@balazsorban44
Copy link
Member

Fix is on the way in Next.js vercel/next.js#61721

@chungweileong94
Copy link
Contributor Author

chungweileong94 commented Feb 7, 2024

Will close this issue, as it has been fixed in the latest NextJS canary release.

@Zelzazor
Copy link

Zelzazor commented Feb 8, 2024

Note: You most likely don't need AUTH_URL or NEXTAUTH_URL anyway, it's not been required for a very long time, unless you want a custom path for your auth route, or behind a proxy.

Thing is, I do use a proxy because I am working with a Docker container and using nginx to deploy the app. What are my options in this case?

EDIT: Nevermind my message, I was able to make the auth work using NEXTAUTH_URL_INTERNAL instead.

@itskaransingh
Copy link

Hi @Zelzazor , can you please tell me how you were able to make the auth work using NEXTAUTH_URL_INTERNAL, thanks.

@irclausen
Copy link

Hi @Zelzazor , can you please tell me how you were able to make the auth work using NEXTAUTH_URL_INTERNAL, thanks.

I was able to apply a fix for local dev at least by changing:

AUTH_URL=***********

to

NEXTAUTH_URL_INTERNAL=***********

in my .env file. If you don't have AUTH_URL perhaps add NEXTAUTH_URL_INTERNAL instead of replacing

@itskaransingh
Copy link

Thanks, btw my error resolved when i shifted to previous version 5.0.0-beta.4 from 5.0.0-beta.8

@bwheeele
Copy link

I am still getting this error. I tried adding AUTH_URL , NEXTAUTH_URL_INTERNAL and still keep getting this error.

@chungweileong94
Copy link
Contributor Author

@bwheeele This is an upstream Next.js bug, which has been fixed in vercel/next.js#61721, and landed in the latest Next.js canary version, but yet to be landed in the stable version.

@paxbowlski
Copy link

@chungweileong94 just installed 14.1.1-canary.73 and it resolved the issue for me. Thank you!

@oscarmylla
Copy link

oscarmylla commented Feb 28, 2024

I've encountered a potential edge case when using the prisma adapter together with prisma accelerate and the following versions in my project:

@prisma/client: ^5.10.2
@prisma/extension-accelerate: ^0.6.3
next-auth: ^5.0.0-beta.13
next: ^14.1.0,

I observed that this issue was resolved when I set the route handler to run on the edge.


This doesn't work:

import { auth } from "@/server/auth";

export const GET = auth(async (req) => {
   const session = req.auth
   ...
   return Response.json({data})
})

This works:

import { auth } from "@/server/auth";

export const runtime = 'edge';

export const GET = auth(async (req) => {
   const session = req.auth
   ...
   return Response.json({data})
})

@philippemiguet
Copy link

Hi @Zelzazor , can you please tell me how you were able to make the auth work using NEXTAUTH_URL_INTERNAL, thanks.

I was able to apply a fix for local dev at least by changing:

AUTH_URL=***********

to

NEXTAUTH_URL_INTERNAL=***********

in my .env file. If you don't have AUTH_URL perhaps add NEXTAUTH_URL_INTERNAL instead of replacing

This is what fixed it for me on "next-auth": "^5.0.0-beta.17"

@IhorAnDev
Copy link

This is what fixed it for me on "next-auth": "^5.0.0-beta.17"

God, bless you! Thanks a million.

@mclbdn
Copy link

mclbdn commented Sep 20, 2024

I am on 4.2.5 and nor AUTH_URL nor NEXTAUTH_URL_INTERNAL solved it for me.

@skywalker282
Copy link

Note: You most likely don't need AUTH_URL or NEXTAUTH_URL anyway, it's not been required for a very long time, unless you want a custom path for your auth route, or behind a proxy.

Not at all, if youremove them and try authenticating with Google, you get an url_mismatch error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream The issue dervies from one of next-auth dependencies
Projects
None yet
Development

No branches or pull requests