相关疑难解决方法(0)

验证 Next.js 中间件中的 JWT 令牌会抛出“找不到模块:无法解析‘加密’”错误

我正在尝试使用 JWT 验证通过中间件进行身份验证,但不幸的是,我遇到了一些无法找到解决方案的错误。

./node_modules/jwa/index.js:3:0
Module not found: Can't resolve 'crypto'

Import trace for requested module:
./node_modules/jws/lib/sign-stream.js
./node_modules/jws/index.js
./node_modules/jsonwebtoken/verify.js
./middleware.ts

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

You're using a Node.js module (crypto) which is not supported in the Edge Runtime.
Learn more: https://nextjs.org/docs/api-reference/edge-runtime
Run Code Online (Sandbox Code Playgroud)

包.json

{
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@emotion/react": "^11.9.3",
    "@emotion/styled": "^11.9.3",
    "@mui/material": "^5.8.6",
    "@prisma/client": "^4.0.0",
    "axios": "^0.27.2",
    "buffer": "^6.0.3",
    "cookie": "^0.5.0",
    "jsonwebtoken": "^8.5.1",
    "next": "12.2.0",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-hook-form": "^7.33.0" …
Run Code Online (Sandbox Code Playgroud)

middleware node.js jwt next.js

3
推荐指数
1
解决办法
4993
查看次数

标签 统计

jwt ×1

middleware ×1

next.js ×1

node.js ×1