nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
24.78k stars 3.49k forks source link

Build fails with v4.18.5 using middleware #6025

Closed aq-saito closed 1 year ago

aq-saito commented 1 year ago

Environment

System: OS: Linux 5.15 Ubuntu 20.04.5 LTS (Focal Fossa) CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700KF Memory: 12.22 GB / 15.53 GB Container: Yes Shell: 5.8 - /bin/zsh Binaries: Node: 16.18.0 - ~/.asdf/installs/nodejs/16.18.0/bin/node Yarn: 1.22.19 - ~/.asdf/installs/nodejs/16.18.0/bin/yarn npm: 8.19.2 - ~/.asdf/plugins/nodejs/shims/npm npmPackages: next: 13.0.6 => 13.0.6 next-auth: 4.18.5 => 4.18.5 react: 18.2.0 => 18.2.0

Reproduction URL

https://github.com/nextauthjs/next-auth-example

Describe the issue

npm run build starts failing to build after upgrading next-auth to v4.18.5 if the project uses next-auth/middleware.

Even the official example repository next-auth-example cannot be built with the latest version of next-auth.

$ npm run build

> build
> next build

info  - Linting and checking validity of types
info  - Creating an optimized production build
Failed to compile.

./node_modules/@babel/runtime/regenerator/index.js
Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation

Import trace for requested module:
./node_modules/@babel/runtime/regenerator/index.js
./node_modules/next-auth/core/errors.js
./node_modules/next-auth/utils/web.js
./node_modules/next-auth/next/middleware.js
./node_modules/next-auth/middleware.js

How to reproduce

$ git clone https://github.com/nextauthjs/next-auth-example
$ cd next-auth-example
$ npm install
$ npm run build

Expected behavior

npm run build is done without any errors.

Nayeem-XTREME commented 1 year ago

Faced same issue after upgrading to 4.18.5

geekyayush commented 1 year ago

I think I am facing the same issue but with version 4.16.4. I opened this issue: https://github.com/nextauthjs/next-auth/issues/6089

benramsay commented 1 year ago

I'm using next-auth for the first time, and I'm having the same problem when building :( Is there any tip, to not be blocked for urgent tasks, while this bug is fixed ? Should I go to an older version (wich one) ? Thx

geekyayush commented 1 year ago

Is there any update on this?

dev-isemo commented 1 year ago

@geekyayush i had the same problem. Just discovered that the bug was fixed with version 4.18.6 i think. Works for me with the latest version 4.18.8 :)

geekyayush commented 1 year ago

@geekyayush i had the same problem. Just discovered that the bug was fixed with version 4.18.6 i think. Works for me with the latest version 4.18.8 :)

Hey @dev-isemo Thanks for the suggestion. I tried after upgrading but still it didn't work. I am trying to deploy it on Cloudflare pages.

Would it be possible for you to share your code or repo? (just the part where you have a boilerplate code) I would really appreciate it.

Thanks!

dev-isemo commented 1 year ago

@geekyayush I think it currently doesnt work with cloudflare cause its an edge runtime (not 100% sure take it with a grain of salt). I am using docker and deploying it on a plain server.

Here is the config which works for me:

Node Version: 18.12.1
Alpine Version: 3.17
NextJS: 13.1.2
Next-auth: 4.18.8
React: 18.2.0

I think you can test it with the most simple middleware e.g.

middleware.js

export { default } from "next-auth/middleware"
geekyayush commented 1 year ago

@dev-isemo I am doing the same exact thing as of now. Deploying it on my own server through docker.

I will surely try that.

evanrosa commented 1 year ago

Is there any update to this? Using v 4.22.3