Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix 'fs module not found' error when using Langchain document loaders in Next.js? [closed]

I am working on an AI project. I am using Langchain and Next.js 13.

I am trying to use the document loaders in langchain to load my PDF, however when I call a loader eg

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

Immediately I get an error:

fs module not found

As per langchain documentation, this should not occur as it states that the APIs support Next.js enviroment.

I have tried using a package(pdf.js) to handle PDF file upload and parsing, but I get an error with this as well.

How can I use langchain document loaders in Next.js?

like image 448
Dr. Ayilara Avatar asked Oct 15 '25 19:10

Dr. Ayilara


1 Answers

I finally understand the issue here.

I was calling it in the browser context but once I moved my code to the API routes(Node) environment, everything worked as expected.

like image 118
Dr. Ayilara Avatar answered Oct 19 '25 00:10

Dr. Ayilara