【问题标题】:Next js showing this error when creating a file name 'middleware' in the root directory. Otherwise the app runs fineNext js 在根目录中创建文件名 \'middleware\' 时显示此错误。否则应用程序运行正常
【发布时间】:2023-01-26 16:24:14
【问题描述】:

错误 - 错误 [TypeError]:类扩展值未定义不是构造函数或 null 在 ../../node_modules/.pnpm/undici@5.11.0/node_modules/undici/lib/fetch/file.js (evalmachine.:5724:19) 在 __require (evalmachine.:14:50) 在 ../../node_modules/.pnpm/undici@5.11.0/node_modules/undici/lib/fetch/formdata.js (evalmachine.:5881:49) 在 __require (evalmachine.:14:50) 在 ../../node_modules/.pnpm/undici@5.11.0/node_modules/undici/lib/fetch/body.js (evalmachine.:6094:35) 在 __require (evalmachine.:14:50) 在 ../../node_modules/.pnpm/undici@5.11.0/node_modules/undici/lib/fetch/response.js (evalmachine.:6510:49) 在 __require (evalmachine.:14:50) 在 (evalmachine.:11635:30) 在 requireFn (file://D:\Nishad@b2g\Frontends\texsupplier-frontend\node_modules\next\dist\compiled\edge-runtime\index.js:1:7079) { 中间件:真

中间件代码

export default function middleware(req){
    
    const cookies = parseCookies()
    let verify =  cookies.token
    let url =  req.url

    if(url.includes('/profile')){
        NextResponse.redirect('http://localhost:3000')
    }
}

【问题讨论】:

  • 你能粘贴中间件代码吗
  • 我已经添加了我的中间件代码。

标签: javascript reactjs next.js


【解决方案1】:

将文件命名为middleware 会导致与 Next.js 使用的一些内部中间件功能发生冲突。 尝试将文件重命名为“middleware_custom”之类的其他名称,这应该可以解决冲突。

【讨论】:

  • 它消除了错误,但我的中间件在路由更改时从不调用。
猜你喜欢
  • 2018-06-05
  • 2020-12-10
  • 1970-01-01
  • 1970-01-01
  • 2017-06-29
  • 2022-08-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多