Build LLM Apps with LangChain.js Loading and preparing data

I keep getting error Error: ENOENT: no such file or directory, open ‘C:\LangChainTest2\test\data\05-versions-space.pdf’

even though the pdf I am aiming for is stored in a different path as per code below, I am a novice and totally appreciate any help, thank you

import “dotenv/config”;

// Peer dependency

import * as parse from “pdf-parse”;

import { PDFLoader } from “langchain/document_loaders/fs/pdf”;

const loader = new PDFLoader(“./data/Test_FAQ_sheet.pdf”);

const rawCS229Docs = await loader.load();

console.log(rawCS229Docs.slice(0, 5));

I figured it out, had to modify path inside index.js in directory “pdf-parse”

1 Like

Hi @dtringa

Welcome to the community.

Thanks for sharing your solution

Hi @dtringa having same issue, and not sure what you mean by " modify path inside index.js" > Can you please give more details about how you managed to rectify this issue, and what it was due to ?

Should this line import * as parse from "pdf-parse"; be updated to read
"import * as parse from "pdf-parser"; (note the r suffix)

I stumbled on a possible solution:
I simply commented out the ‘peer dependency’
//import * as parse from "npm:pdf-parse";

Hi for me issue was with path to pdf in index.js at line 14 (node_modules/pdf-parse/index.js)
//let PDF_FILE = ‘./test/data/05-versions-space.pdf’;

I updated it to use my path and was able to run it.
Hope this helps