nextauthjs / next-auth

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

Error: Module not found: Can't resolve 'crypto'" #10685

Closed aifirstd3v closed 4 months ago

aifirstd3v commented 4 months ago

Adapter type

@auth/drizzle-adapter

Environment

System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M
  Binaries:
    Node: 20.11.0 - ~/Library/pnpm/node
    Yarn: 1.22.22 - ~/Library/pnpm/yarn
    npm: 10.5.2 - ~/Library/pnpm/npm
    pnpm: 9.0.5 - ~/Library/pnpm/pnpm
    bun: 1.1.4 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 124.0.6367.61
    Chrome Canary: 126.0.6433.0
    Edge: 124.0.2478.51
    Safari: 17.4.1
  npmPackages:
    @auth/core: ^0.30.0 => 0.30.0 
    @auth/drizzle-adapter: ^1.0.0 => 1.0.0
    next: 14.2.2 => 14.2.2 
    next-auth: ^5.0.0-beta.16 => 5.0.0-beta.16 
    react: ^18 => 18.2.0 

Reproduction URL

none

Describe the issue

import { Hono, Context } from "hono";
import { handle } from "hono/vercel";
import { authHandler, initAuthConfig, verifyAuth } from "@hono/auth-js"

import { getAuthConfig } from "@/auth.config";

export const runtime = "edge"; <--- This is the problem

const app = new Hono().basePath("/api");

app.use("*", initAuthConfig(getAuthConfig));
app.use("/auth/*", authHandler());

export type AppType = typeof route;

export const GET = handle(app);
export const POST = handle(app);

When working with Hono.JS and Edge runtime with @auth+drizzle-adapter@1.0.0 ,

I got "Error: Module not found: Can't resolve 'crypto'"

If I downgrade the version such as 0.8.2 or 0.9.0, It works!

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module: ./node_modules/.pnpm/@auth+drizzle-adapter@1.0.0/node_modules/@auth/drizzle-adapter/index.js ./auth.config.ts ./app/api/[[...route]]/route.ts ./node_modules/.pnpm/next@14.2.2_react-dom@18.2.0_react@18.2.0__react@18.2.0/node_modules/next/dist/build/webpack/loaders/next-edge-app-route-loader/index.js?

How to reproduce

 "dependencies": {
    "@auth/core": "^0.30.0",
    "@auth/drizzle-adapter": "^1.0.0",
    "@hono/auth-js": "^1.0.3",
    "@hono/zod-validator": "^0.2.1",
    "@neondatabase/serverless": "^0.9.1",
    "@paralleldrive/cuid2": "^2.2.2",
    "@radix-ui/react-avatar": "^1.0.4",
    "@radix-ui/react-dropdown-menu": "^2.0.6",
    "@radix-ui/react-slot": "^1.0.2",
    "@tanstack/react-query": "^5.31.0",
    "class-variance-authority": "^0.7.0",
    "clsx": "^2.1.0",
    "date-fns": "^3.6.0",
    "drizzle-orm": "^0.30.9",
    "hono": "^4.2.6",
    "lucide-react": "^0.372.0",
    "nanoid": "^5.0.7",
    "next": "14.2.2",
    "react": "^18",
    "react-dom": "^18",
    "tailwind-merge": "^2.3.0",
    "tailwindcss-animate": "^1.0.7",
    "zod": "^3.23.0"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "autoprefixer": "^10.4.19",
    "dotenv": "^16.4.5",
    "drizzle-kit": "^0.20.17",
    "eslint": "^9",
    "eslint-config-next": "14.2.2",
    "pg": "^8.11.5",
    "postcss": "^8",
    "tailwindcss": "^3.4.3",
    "typescript": "^5"
  },

Expected behavior

No Error

github-actions[bot] commented 4 months ago

We could not detect a valid reproduction link. Make sure to follow the bug report template carefully.

Why was this issue closed?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We need a link to a public GitHub repository. Example: (NextAuth.js example repository).

The bug template that you filled out has a section called "Reproduction URL", which is where you should provide the link to the reproduction.

What should I do?

Depending on the reason the issue was closed, you can do the following:

In general, assume that we should not go through a lengthy onboarding process at your company code only to be able to verify an issue.

My repository is private and cannot make it public

In most cases, a private repo will not be a sufficient minimal reproduction, as this codebase might contain a lot of unrelated parts that would make our investigation take longer. Please do not make it public. Instead, create a new repository using the templates above, adding the relevant code to reproduce the issue. Common things to look out for:

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps by opening a new issue.

I think my reproduction is good enough, why aren't you looking into it quickly?

We look into every issue and monitor open issues for new comments.

However, sometimes we might miss a few due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources