下一个连接错误:无法使用next-connect在我的next.js项目中使用JavaScript路由

rggaifut  于 2023-08-04  发布在  Java
关注(0)|答案(1)|浏览(112)

我的下一个版本是13.4.5(最新)我的下一个连接版本是1.0.0(最新)

在pages>API>auth> signup.js中:

import { createRouter } from "next-connect"

const handler = createRouter()

handler.post(async (req, res) => {
    res.send("Welcome from the signup page.")
})

export default handler

字符串
当我做一个帖子requesst使用 Postman -http://localhost:3000/api/auth/signup这是错误:错误[TypeError]:解析器不是函数
我正确地导出了函数,正如你所看到的,我也尝试了下面的代码:

import nc from "next-connect"

const handler = nc()

handler.post(async (req, res) => {
    res.send("Welcome from the signup page.")
})

export default handler

这是一个错误:错误[TypeError]:(0,next_connect__WEBPACK_IMPORTED_MODULE_0__.default)不是函数

我想得到欢迎(“欢迎从注册API”)的消息,在代码中,并使路由工作正常与下一个连接

3df52oht

3df52oht1#

我已经在最新版本的next-connect(pakage)中解决了上述错误,如果你必须使用javasscript,你必须这样使用:

import { createRouter } from "next-connect"
const router = createRouter()
router.post(async (req, res) => {
    res.send("Hello, this is from the next-connect router")
})
export default router.handler()

字符串
现在根据上面的代码发送POST请求(使用Postman),它将工作

相关问题