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

Does not work in BGSW using Plasmo framework #2

Open
Fiattarone opened this issue Nov 27, 2023 · 4 comments
Open

Does not work in BGSW using Plasmo framework #2

Fiattarone opened this issue Nov 27, 2023 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@Fiattarone
Copy link

Fiattarone commented Nov 27, 2023

Environment

Framework: Plasmo 0.84.0
Client side Chrome Browser Extension

Reproduction

Can be reproduced by creating a BGSW in the Plasmo framework and importing unpdf. Error message is:

🔴 ERROR | Build failed. To debug, run plasmo dev --verbose.
🔴 ERROR | Failed to resolve 'unpdf/pdfjs' from './node_modules/.pnpm/[email protected]/node_modules/unpdf/dist/index.mjs'

Describe the bug

Bug is as aforementioned: unpdf seems to be looking for a pdfjs dependency that is inaccessible.

Additional context

No response

Logs

No response

@johannschopplich
Copy link
Collaborator

Mmh, interesting. Which bundler does Plasmo use? unpdf provides a sub path export unpdf/pdfjs:

"./pdfjs": {

Seems to me more like a Plasmo issue than unpdf. I have tested unpdf with esbuild, Rollup and more, which all correctly bundle unpdf/pdfjs.

Could you please provide a reproducible example?

@Fiattarone
Copy link
Author

Bundler used is https://parceljs.org/ I believe... I know that I couldn't get plasmo to work with pdfjs either, so this very well could be a plasmo issue.

Will drop an example in here when I get a moment, sorry about not including that the first round.

My current workaround is to use unpdf on my proxy (vercel) server (normally used for other things) but this is really just to continue development, it would be really not-prime to handle everyone's PDF shenanigans when they could be doing it themselves on the client side.

@Fiattarone
Copy link
Author

Hey there, sorry for taking so long!

https://github.com/Fiattarone/unpdf-plasmo-example under core/test.ts is where I put it

Or, even easier to reproduce with a one-liner:

git clone [email protected]:Fiattarone/unpdf-plasmo-example.git  --recurse-submodules &&
cd unpdf-plasmo-example &&
pnpm install &&
pnpm dev

fails upon compiling

If this is more of an issue with plasmo, I'll take it up with them--just let me know!

@johannschopplich
Copy link
Collaborator

Hi @Fiattarone, thanks for the reproduction. I tried to import the pdfjs subpath export, but somehow the Parcel bundler doesn't seem to resolve the dependency. A quick look at Parcel's dependency resolution docs didn't help.

Even if we point to the PDF.js source file, the bundler fails to locate it:

import { configureUnPDF, extractText } from "unpdf"

configureUnPDF({
  pdfjs: () => import("unpdf/dist/pdfjs.mjs"),
});

Sorry, but at the moment, I don't have a fix for the Plasmo framework. Noted that Vite (using Rollup) and esbuild correctly resolves the import…

@johannschopplich johannschopplich added the help wanted Extra attention is needed label Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants