Use standard pdfjs-dist entry point instead of legacy subpath
- Ngôn ngữ chính
- TypeScript
- Star
- 395
- Fork
- 39
- Merge trung bình
- 7 giờ 7 phút
- Pull request đã merge (30 ngày)
- 12
Mô tả
## Problem
Lector internally imports from `pdfjs-dist/legacy/build/pdf.mjs`:
```js
// src/lib/pdfjs.ts
pdfJsPromise = import('pdfjs-dist/legacy/build/pdf.mjs');
```
This is a different module instance than what `import('pdfjs-dist')` returns. In pdfjs-dist v5, each build entry has its own `GlobalWorkerOptions` class with private static fields, so configuring the worker on the standard entry point has no effect on lector's internal instance:
```ts
import { GlobalWorkerOptions } from "pdfjs-dist";
GlobalWorkerOptions.workerSrc = new URL(
"pdfjs-dist/build/pdf.worker.mjs",
import.meta.url
).toString();
// ^ This does NOT affect lector — it uses a separate GlobalWorkerOptions
```
This causes `No "GlobalWorkerOptions.workerSrc" specified.` at runtime (related: #17).
## Suggested fix
In `src/lib/pdfjs.ts`, change the import to the standard entry point:
```diff
- pdfJsPromise = import('pdfjs-dist/legacy/build/pdf.mjs');
+ pdfJsPromise = import('pdfjs-dist');
```
This way consumers configure one `GlobalWorkerOptions` and lector sees it. Projects that need the legacy build can still alias `pdfjs-dist` → `pdfjs-dist/legacy/build/pdf.mjs` in their bundler config — but the default should use the package's declared main entry.
## Workaround
For anyone hitting this today, add a Vite resolve alias:
```ts
resolve: {
alias: {
"pdfjs-dist/legacy/build/pdf.mjs": "pdfjs-dist/build/pdf.mjs",
},
}
```
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.