Remove Unnecessary document Injection to Fix Prerendering Error
**Describe the bug**
When using the npm package from [opengovsg/pdf2md](https://github.com/opengovsg/pdf2md) for PDF to Markdown conversion, a `TypeError` is thrown: `document.createTextNode is not a function`. This error occurs during the prerendering phase with Next.js pages.
**To Reproduce**
1. npm i pdf2md
2. next dev run the project
3. Observe the error: `Error occurred prerendering page "/app/dashboard/xxx"`.
**Expected behavior**
Do not interfere with the development mode (next dev) or the build process (build) in a Next.js application.
**Additional context**
I discovered that this issue might be related to `./util/dom-stubs` injecting `document`, affecting Next.js elsewhere. This was introduced in [Issue #11](https://github.com/opengovsg/pdf2md/issues/11) on the repository. With pdf.js version 4.0 having removed this file, and `pdf2md` no longer using `pdf.js-dist` post-version 2.0, could the related code be removed?
关闭于 2024-12-12 0 条评论