Type ‘HumanMessage’ is not assignable to type ‘BaseMessageLike’. Type ‘HumanMessage’ is not assignable to type ‘BaseMessage’

I am not sure how to fix this, as all parameters are being met and and imports are taken into account and decencies have been installed can someone please provide some insight and or a solution. for context. I am building a project from a that was uploaded in early 2024 and it is march 2025 if that may help. here are pictures.

Error


./src/app/api/quizz/generate/route.ts:94:48
Type error: Type 'HumanMessage' is not assignable to type 'BaseMessageLike'.
  Type 'HumanMessage' is not assignable to type 'BaseMessage'.
    The types returned by '_getType()' are incompatible between these types.
      Type 'import("/Users/connormullins/Documents/Quiz iteration saves/quizz-ai-tutorial latest/node_modules/.pnpm/@[email protected][email protected][email protected]_/node_modules/@langchain/core/dist/messages/base").MessageType' is not assignable to type 'import("/Users/connormullins/Documents/Quiz iteration saves/quizz-ai-tutorial latest/node_modules/.pnpm/@[email protected][email protected][email protected]_/node_modules/@langchain/core/dist/messages/base").MessageType'.
        Type '"developer"' is not assignable to type 'MessageType'.

  92 |     });
  93 |
> 94 |     const result: any = await runnable.invoke([message]);
     |                                                ^
  95 |     console.log(result);
  96 |
  97 |     const { quizzId } = await saveQuizz(result.quizz);

I am running HummanMessage from Langchain for a AI quiz Generator and cannot run my build properly due to this error. making it so I cannot deploy onto vercel.

import { NextRequest, NextResponse } from "next/server";

import { ChatOpenAI } from "@langchain/openai";
import { HumanMessage } from "@langchain/core/messages";

import { PDFLoader } from "langchain/document_loaders/fs/pdf";
import { JsonOutputFunctionsParser } from "langchain/output_parsers";

import saveQuizz from "./saveToDb";

export async function POST(req: NextRequest) {
  const body = await req.formData();
  const document = body.get("pdf");

  try {
    const pdfLoader = new PDFLoader(document as Blob, {
      parsedItemSeparator: " ",
    });
    const docs = await pdfLoader.load();

    const selectedDocuments = docs.filter(
      (doc) => doc.pageContent !== undefined
    );
    const texts = selectedDocuments.map((doc) => doc.pageContent);

    const prompt =
      "given the text which is a summary of the document, generate a quiz based on the text. Return json only that contains a quizz object with fields: name, description and questions. The questions is an array of objects with fields: questionText, answers. The answers is an array of objects with fields: answerText, isCorrect.";

    if (!process.env.OPENAI_API_KEY) {
      return NextResponse.json(
        { error: "OpenAI API key not provided" },
        { status: 500 }
      );
    }

    const model = new ChatOpenAI({
      openAIApiKey: process.env.OPENAI_API_KEY,
      modelName: "gpt-4-1106-preview",
    });

    const parser = new JsonOutputFunctionsParser();
    const extractionFunctionSchema = {
      name: "extractor",
      description: "Extracts fields from the output",
      parameters: {
        type: "object",
        properties: {
          quizz: {
            type: "object",
            properties: {
              name: { type: "string" },
              description: { type: "string" },
              questions: {
                type: "array",
                items: {
                  type: "object",
                  properties: {
                    questionText: { type: "string" },
                    answers: {
                      type: "array",
                      items: {
                        type: "object",
                        properties: {
                          answerText: { type: "string" },
                          isCorrect: { type: "boolean" },
                        },
                      },
                    },
                  },
                },
              },
            },
          },
        },
      },
    };

    const runnable = model
      .bind({
        functions: [extractionFunctionSchema],
        function_call: { name: "extractor" },
      })
      .pipe(parser);

    const message = new HumanMessage({
      content: [
        {
          type: "text",
          text: prompt + "n" + texts.join("n"),
        },
      ],
    });

    const result: any = await runnable.invoke([message]);
    console.log(result);

    const { quizzId } = await saveQuizz(result.quizz);

    return NextResponse.json({ quizzId }, { status: 200 });
  } catch (e: any) {
    return NextResponse.json({ error: e.message }, { status: 500 });
  }
}