我有一个如下的获取端点:
import { NextResponse } from 'next/server';
import connection from '@config/db';
export async function GET(req: Request, context: { params: { providerId: number } }) {
const providerId = await context.params.providerId;
// Placeholder for current user ID (replace this with actual user ID from session/auth)
const currentUserId = 2; // Change to dynamically fetch from your auth system
...
它有效,但我收到此错误:错误:路由“/api/appProviders/listProvider/[providerId]”已使用params.providerId
。params
在使用其属性之前应等待。了解更多信息: https:
有没有什么办法可以摆脱它?谢谢
我尝试了各种方法,但似乎找不到解决方案
1
最佳答案
2
谢谢你,大卫,有时解决方案就在你眼前:
只需安装:
npx @next/codemod@latest next-async-request-api 。
|
首先,您要安装的软件包由于覆盖而出现错误,首先在 cmd 中输入 npm -v 或 npm –version,首先在您的项目中输入 ncu -u,它将更新您所有最新版本的节点模块,如包和 nextjs 为下面的新版本,然后在 package.json 中进行更改
"packageManager": "npm@anyversion", // mention there your npm version example mine "npm@10.9.0"
"overrides": {
"react": "$react",
"react-dom": "$react-dom"
},
}
then save it and run npm install why we are doing this means for nextjs 15 and react 19 is in development every time if u want install any package which leads error by this you can now use only npm install which easy and don't give errors
执行此操作并安装
npx @next/codemod@latest next-async-request-api .
后
import { NextResponse } from 'next/server';
import connection from '@config/db';
export async function GET(req: Request, context: { params: Promise<{ providerId: number }> }) {
const {providerId} = await context.params.providerId;
您应该为参数添加 Promise
|
–
|