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

[BUG] NextAuth errors with [unenv] crypto.createCipheriv is not implemented yet! #206

Open
RUNFUNRUN opened this issue Dec 26, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@RUNFUNRUN
Copy link

RUNFUNRUN commented Dec 26, 2024

cloudflare/workerd#3277 (comment)

Describe the bug

When next-auth is used and next-auth related functions are executed, the following error occurs.

[wrangler:err] TypeError: Cannot assign to read only property 'cache' of object '#<eA>'
    at new CustomRequest (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/server-functions/default/handler.mjs:20:18)
    at new $ (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/middleware/handler.mjs:797:62)
    at o5 (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/middleware/handler.mjs:5655:16)
    at so (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/middleware/handler.mjs:5797:19)
    at Object.handler (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/middleware/handler.mjs:5782:20)
    at null.<anonymous> (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/middleware/handler.mjs:1268:174)
    at Object.wrap (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/middleware/handler.mjs:1194:20)
    at null.<anonymous> (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/middleware/handler.mjs:1266:276)
    at null.<anonymous> (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/middleware/handler.mjs:1106:25)
    at i2.with (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/middleware/handler.mjs:6421:25)

Steps to reproduce

  1. clone this repository https://github.com/RUNFUNRUN/opennext-cf
  2. install packages
bun i
  1. copy env
cp sample.env .env

(Environment variables can be reproduced as in the sample.)
4. run preview

bun run preview
  1. open http://localhost:8787/
    If I try deleting middleware.ts, I can access http://localhost:8787/ , but when I press the Sign In button, I get the same error.

Expected behavior

next-auth works

@opennextjs/cloudflare version

0.3.2

Wrangler version

3.99.0

next info output

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Thu Nov 14 18:15:21 PST 2024; root:xnu-11215.41.3~13/RELEASE_ARM64_T6041
  Available memory (MB): 24576
  Available CPU cores: 12
Binaries:
  Node: 23.5.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: 9.14.2
Relevant Packages:
  next: 15.1.3 // Latest available version is detected (15.1.3).
  eslint-config-next: 15.1.3
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.2
Next.js Config:
  output: N/A

Additional context

No response

@RUNFUNRUN RUNFUNRUN added bug Something isn't working triage labels Dec 26, 2024
vicb added a commit that referenced this issue Dec 27, 2024
@vicb
Copy link
Contributor

vicb commented Dec 27, 2024

Can you try to install the following version of the adapter: https://pkg.pr.new/@opennextjs/cloudflare@212

It comes from PR #212 and should solve the issue

@RUNFUNRUN
Copy link
Author

RUNFUNRUN commented Dec 28, 2024

Thank you very much.
This error has been resolved.

However, I got another error.
Should I send it as a separate issue?
This may not be an opennext issue

✘ [ERROR] [auth][error] Error: [unenv] crypto.createCipheriv is not implemented yet!


✘ [ERROR] at createNotImplementedError (file:///Users/runfunrun/projects/test/opennext-cf/.wrangler/tmp/dev-P0rOeD/worker.js:69:10)

      at fn
  (file:///Users/runfunrun/projects/test/opennext-cf/node_modules/unenv/runtime/_internal/utils.mjs:26:11)
      at null.<anonymous>
  (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/.next/standalone/.next/server/chunks/192.js:25:22170)
      at eG
  (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/.next/standalone/.next/server/chunks/192.js:25:22293)
      at tP.encrypt
  (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/.next/standalone/.next/server/chunks/192.js:25:36728)
      at async tO.encrypt
  (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/.next/standalone/.next/server/chunks/192.js:25:37464)
      at async tG
  (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/.next/standalone/.next/server/chunks/192.js:25:50675)
      at async n8
  (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/.next/standalone/.next/server/chunks/192.js:392:26349)
      at async Object.create
  (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/.next/standalone/.next/server/chunks/192.js:392:27246)
      at async s_
  (file:///Users/runfunrun/projects/test/opennext-cf/.open-next/.next/standalone/.next/server/chunks/192.js:392:47901)

vicb added a commit that referenced this issue Dec 28, 2024
@vicb vicb changed the title [BUG] TypeError: Cannot assign to read only property 'cache' of object '#<eA>' [BUG] NewtAuth errors with [unenv] crypto.createCipheriv is not implemented yet! Dec 28, 2024
@vicb
Copy link
Contributor

vicb commented Dec 28, 2024

Should I send it as a separate issue?

It's ok to re-use this issue - I have changed the title to reflect what's need to be done here.

crypto.createCipheriv is not yet implemented by workerd but we're working on it. Should be available early 2025.

@RUNFUNRUN
Copy link
Author

I see.
Thanks<3

@Macil
Copy link

Macil commented Jan 26, 2025

I've run into this same issue while trying to use opennextjs-cloudflare with next-auth.

I notice that the Error: [unenv] crypto.createCipheriv is not implemented yet! error gets thrown from jose/src/runtime/node/encrypt.ts, which surprises me because the library jose has a separate implementation using the SubtleCrypto API instead of crypto.createCipheriv (jose/src/runtime/browser/encrypt.ts) which is meant to be used in not only browsers but also workerd (jose/package.json#L85). I'm not sure why the node version of the package is being used instead of the workerd version.

If I edit node_modules/jose/package.json so all of the "import"/"main" fields are equal to the "workerd"/"browser" fields so that the workerd/browser version is used instead of the node version, then this issue is solved. (Though next I have an issue where next-auth always redirects to https://localhost:8787/... URLs instead of using http:// during sign-in, which I've given up on trying to figure out.)

@vicb
Copy link
Contributor

vicb commented Jan 26, 2025

@Macil do you have a repo with a repro? Can I also ask the version of Next you use?

@Macil
Copy link

Macil commented Jan 26, 2025

Here's a reproduction repo: https://github.com/Macil/opennext-cf-next-auth-bug-repro

This is using Next 14.2.23, set up using the npm create cloudflare@latest -- my-next-app --framework=next --experimental command from the OpenNext docs.

@vicb vicb changed the title [BUG] NewtAuth errors with [unenv] crypto.createCipheriv is not implemented yet! [BUG] NextAuth errors with [unenv] crypto.createCipheriv is not implemented yet! Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

4 participants