Type "{ params: { id: string; docId: string; }; }" is not a valid type for the function's second arg
Answered
Horned oak gall posted this in #help-forum
Horned oak gallOP
I receive the "is not a valid type for the function's second arg" error when trying to deploy a nextjs 15.2.2 app. Tried all solutions, ai tools, etc, however, couldn't fix it. Below is the function:
export async function GET(
request: NextRequest,
{ params }: { params: { id: string, docId: string } }
) {
try {
const applicationId = params.id;
const documentId = params.docId;
if (!applicationId || !documentId) {
return NextResponse.json({
success: false,
error: 'Application ID and Document ID are required'
}, { status: 400 });
}
export async function GET(
request: NextRequest,
{ params }: { params: { id: string, docId: string } }
) {
try {
const applicationId = params.id;
const documentId = params.docId;
if (!applicationId || !documentId) {
return NextResponse.json({
success: false,
error: 'Application ID and Document ID are required'
}, { status: 400 });
}
20 Replies
@Anay-208 | Ping in replies https://nextjs.org/docs/app/building-your-application/upgrading/version-15#params--searchparams
Horned oak gallOP
I did all the changes accordingly, still receive the same error
Can you share updated code & error?
@Anay-208 | Ping in replies Can you share updated code & error?
Horned oak gallOP
import { NextRequest, NextResponse } from 'next/server';
import path from 'path';
import fs from 'fs';
import { pool } from '@/lib/db-config';
export async function GET(
request: NextRequest,
context: { params: Promise<{ id: string; docId: string }> }
) {
const { id: applicationId, docId: documentId } = await context.params;
if (!applicationId || !documentId) {
return NextResponse.json({
success: false,
error: 'Application ID and Document ID are required'
}, { status: 400 });
}
try {
// Query database for document
const documentQuery = await pool.query(`
SELECT * FROM documents
WHERE id = $1 AND application_id = $2
`, [documentId, applicationId]);
if (documentQuery.rowCount === 0) {
return NextResponse.json({
success: false,
error: 'Document not found'
}, { status: 404 });
}
const document = documentQuery.rows[0];
const filePath = document.path;
// Check if file exists
if (!fs.existsSync(filePath)) {
return NextResponse.json({
success: false,
error: 'File not found on server'
}, { status: 404 });
}
// Read file and serve it
const fileBuffer = fs.readFileSync(filePath);
// Determine content type based on file extension
const fileExtension = path.extname(filePath).toLowerCase();
let contentType = 'application/octet-stream'; // Default
if (['.jpg', '.jpeg'].includes(fileExtension)) contentType = 'image/jpeg';
else if (fileExtension === '.png') contentType = 'image/png';
else if (fileExtension === '.pdf') contentType = 'application/pdf';
else if (['.doc', '.docx'].includes(fileExtension)) contentType = 'application/msword';
// Return file as response
return new NextResponse(fileBuffer, {
headers: {
'Content-Type': contentType,
'Content-Disposition': `inline; filename="${document.original_name || path.basename(filePath)}"`,
},
});
} catch (error: any) {
console.error('Error retrieving document file:', error);
return NextResponse.json({
success: false,
error: error.message
}, { status: 500 });
}
}
Horned oak gallOP
I fixed it! I had to edit also the file
/documents/route.ts
not only the /documents/[docId]/route.ts
I changed the code
{ params }: { params: { id: string } }
to { params }: { params: Promise<{ id: string, docId: string }> }
even if in the error/terminal it indicates that type error in "/documents/[docId]/route.ts" has an invalid "GET" export, it was not sufficient to change only that file! changing it in "/documents/route.ts" fixed the problem! Spent almost 24 hours on this
@Anay-208 | Ping in replies - thank you also!
@Horned oak gall I fixed it! I had to edit also the file /documents/route.ts not only the /documents/[docId]/route.ts
yes that was the only thing needed.
I got a call and forgot to send doc link
I got a call and forgot to send doc link
Answer
the message where I sent the link
Horned oak gallOP
yes, can you share also the link here that you were refering to?
You marked the wrong one btw