[BUG] Using PDF.js (pdfjs-dist) in Plasmo project generates file with name "_empty.<random number>.js" that is reserved by the system
What happened?
Tried in both background index.ts and content scripts, both have the issue.
My code:
import * as pdfjsLib from 'pdfjs-dist';
pdfjsLib.GlobalWorkerOptions.workerSrc = `//mozilla.github.io/pdf.js/build/pdf.worker.js`;
const pdf = await pdfjsLib.getDocument(msg.pdfUrl).promise;
const numPages = pdf.numPages;
let fullText = '';
for (let pageNumber = 1; pageNumber <= numPages; pageNumber++) {
const page = await pdf.getPage(pageNumber);
const textContent = await page.getTextContent();
textContent.items.forEach(item => {
fullText += item.str;
});
}
When the extension is compiled and loaded in Chrome, Chrome pops an alert saying:
Failed to load extension File ~/Products/GPTPlugin/gpt-plugin/build/chrome-mv3-dev Error Cannot load extension with file or directory name _empty.c3437ec2.js. Filenames starting with "_" are reserved for use by the system. Could not load manifest.
Version
Latest
What OS are you seeing the problem on?
MacOSX
What browsers are you seeing the problem on?
Chrome
Relevant log output
No log because the error occurs when the extension is loaded
(OPTIONAL) Contribution
- [ ] I would like to fix this BUG via a PR
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
- [X] I checked the current issues for duplicate problems.
Is there any update regarding this bug?
I have same issue using pdfjs-dist
I solved error by using
import { pdfjs } from "react-pdf"
pdfjs.GlobalWorkerOptions.workerSrc = //cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.js
instead of
import * as pdfjs from 'pdfjs-dist'
Same here. Tried a few different packages pdfjs-dist, pdf-text-reader, couldn't get any of these pdf readers to extract text when using Plasmo.
What's the purpose of _empty file and why is plasmo generating it?
Experiencing the same issue with pdfjs-dist. On Plasmo v0.86.2
I've come across this issue with other packages as well. Here's a temporary workaround that automatically deletes _empty files. Doesn't seem to create any problems:
npm install --save-dev concurrently
npm install --save-dev nodemon
And then in your package.json (for Windows) update scripts:
"scripts": {
"dev": "concurrently \"nodemon --watch build/chrome-mv3-dev/_empty*.js --exec del /f build\\chrome-mv3-dev\\_empty* \" \"plasmo dev\"",
"build": "plasmo build",
"postbuild": "del /f build\\chrome-mv3-prod\\_empty*",
"test": "plasmo test"
},
I've come across this issue with other packages as well. Here's a temporary workaround that automatically deletes
_emptyfiles. Doesn't seem to create any problems:npm install --save-dev concurrently npm install --save-dev nodemonAnd then in your package.json (for Windows) update
scripts:"scripts": { "dev": "concurrently \"nodemon --watch build/chrome-mv3-dev/_empty*.js --exec del /f build\\chrome-mv3-dev\\_empty* \" \"plasmo dev\"", "build": "plasmo build", "postbuild": "del /f build\\chrome-mv3-prod\\_empty*", "test": "plasmo test" },
It worked, thanks so much!