Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDFLoader not working #615

Closed
neebdev opened this issue Apr 4, 2023 · 6 comments · Fixed by #622
Closed

PDFLoader not working #615

neebdev opened this issue Apr 4, 2023 · 6 comments · Fixed by #622

Comments

@neebdev
Copy link
Contributor

neebdev commented Apr 4, 2023

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "UnknownErrorException: The browser/environment lacks native support for critical functionality used by the PDF.js library (e.g. Path2D and/or ReadableStream); please use a legacy-build instead.".] {
code: 'ERR_UNHANDLED_REJECTION'
}
Usage:
import { PDFLoader } from "langchain/document_loaders";
export const run = async () => {
const loader = new PDFLoader("src/sample.pdf");
const docs = await loader.load();
console.log(docs);
};
run();

@neebdev
Copy link
Contributor Author

neebdev commented Apr 4, 2023

solved by changing const { default: mod } = await import("pdfjs-dist"); to const { default: mod } = await import("pdfjs-dist/legacy/build/pdf.js"); in document_loaders/pdf.js.

@nfcampos
Copy link
Collaborator

nfcampos commented Apr 4, 2023

@neebdev hi, which environment are you running this on? Node? if so, which version

@neebdev
Copy link
Contributor Author

neebdev commented Apr 4, 2023

Node v18.12.1

@felipetodev
Copy link
Contributor

same error with node@18.15.0 / langchain@0.0.48 / pdfjs-dist@3.5.141

@nfcampos nfcampos linked a pull request Apr 5, 2023 that will close this issue
@nfcampos
Copy link
Collaborator

nfcampos commented Apr 5, 2023

I've opened a PR that will let you customise which build of pdfjs is used, see #622

@Hormold
Copy link

Hormold commented Apr 5, 2023

Same problem on node 18.4, macos darwin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants