plasmo icon indicating copy to clipboard operation
plasmo copied to clipboard

[BUG] Using PDF.js (pdfjs-dist) in Plasmo project generates file with name "_empty.<random number>.js" that is reserved by the system

Open felixswang opened this issue 1 year ago • 10 comments

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.

felixswang avatar Apr 11 '24 00:04 felixswang

Is there any update regarding this bug?

felixswang avatar Apr 23 '24 20:04 felixswang

I have same issue using pdfjs-dist

123wwwa avatar Apr 26 '24 21:04 123wwwa

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'

123wwwa avatar Apr 29 '24 08:04 123wwwa

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?

muqsitnawaz avatar May 16 '24 00:05 muqsitnawaz

Experiencing the same issue with pdfjs-dist. On Plasmo v0.86.2

lkuo117 avatar Jun 22 '24 01:06 lkuo117

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"
  },

DavidRobles96 avatar Aug 14 '24 03:08 DavidRobles96

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"
  },

It worked, thanks so much!

happydrew avatar Oct 14 '24 12:10 happydrew