arkokoley / pdfvuer

A PDF viewer for Vue using Mozilla's PDF.js that supports both Vue2 and Vue3
https://arkokoley.github.io/pdfvuer
MIT License
914 stars 131 forks source link

worker files missing #68

Closed pixelpaulaus closed 3 years ago

pixelpaulaus commented 4 years ago

after upgrading to the latest version 1.7.1 It seems some files are no longer included when i build for production.

they seem to be files ending in .worker.js

example... when using the module.. this file loads: invoices~quotes~sales.2a8b8dd7.js

when it is set to view a PDF this file loads: invoices~quotes~sales.2a8b8dd7.worker.js

but a 404 is returned, because the file was never built in production, and is also not available in development.

i am just using the latest vue-cli

joepsyko commented 4 years ago

I found the same problem a couple of minutes ago

pixelpaulaus commented 4 years ago

I found the same problem a couple of minutes ago

I have been trying to figure it out for a while now, with no luck. If you make any progress on it, please let me know.

joepsyko commented 4 years ago

For what it worth, if I manually copy the file node_modules/pdfjs-dist/build/pdf.worker.js into my dist folder and name it 11.worker.js it works.

This is not a workaround, iti's just a piece of information for someone who can help us solve the problem.

pixelpaulaus commented 4 years ago

this is so anoying. i am about to move to another vue pdf viewer, uneless anyone can assist? @arkokoley

joepsyko commented 4 years ago

Do you need to update to the latest version because of a bug?

pixelpaulaus commented 4 years ago

correct. older versions of this were not working on certain platforms. so i upgraded, now none work :-(

arkokoley commented 4 years ago

@pixelpaulaus @joepsyko I'm working on this issue at the moment. I'll release a working version by today.

joepsyko commented 4 years ago

ok, so I understand your frustration

pixelpaulaus commented 4 years ago

Hi @arkokoley , do you need any help with anything? happy to help if i can

nicholaszuccarelli commented 4 years ago

Same problem with me.

pixelpaulaus commented 4 years ago

can anyone recommend another pdf package for vue that works well?

niklaszantner commented 4 years ago

@pixelpaulaus you could give https://www.npmjs.com/package/vue-pdf a try.

lochstar commented 4 years ago

This fix should be as simple as adding:

const PdfjsWorker = require('worker-loader?esModule=false!pdfjs-dist/build/pdf.worker.js');

if (typeof window !== 'undefined' && 'Worker' in window) {
  pdfjsLib.GlobalWorkerOptions.workerPort = new PdfjsWorker();
}

At the top of Pdfvuer.vue after the imports. You'll need to add worker-loader as a dependency.

Drumstix42 commented 4 years ago

I had to revert to 1.6.1 to be able to use this component.

Is this still being maintained/managed?

afv commented 4 years ago

@pixelpaulaus you could give https://www.npmjs.com/package/vue-pdf a try.

vue-pdf does not have the text layer working out-of-the-box :(

Had to downgrade to 1.6.1 too.

arkokoley commented 3 years ago

Fix for this:

add worker-loader

npm i --save worker-loader

Add this to your webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.worker\.js$/,
        use: {
          loader: 'worker-loader',
          options: {
            filename: '[name].worker.js'
          }
        }
      },
     ...
  ]

UPDATE:

Also add this to your App.vue or main.js

  /* eslint-disable */
  var pdfwoker = require('worker-loader!pdfjs-dist/build/pdf.worker')
  /* eslint-enable */
TehEbil commented 3 years ago

Hi,

we tried adding this into our webpack (vue.config.js), but we still get the 572.worker.js (<-- random number) is missing, we installed worker-loader via yarn and added it to both, webpackConfig and also tried it to add it to webchain, but neither of those changed the error. Are we missing something, or do you have another idea why it is not working for us?

nicholaszuccarelli commented 3 years ago

Upgrading to 1.7.3 and I can't even load any PDFs in development mode.

Uncaught (in promise) Error: Setting up fake worker failed: "Cannot load script at: http://localhost:8080/app.worker.js" I'm not sure how I am meant to bind app.worker.js.

I installed worker-loader and updated my Webpack settings as described ^

arkokoley commented 3 years ago

@nicholaszuccarelli, @TehEbil

            filename: 'app.worker.js'   // <---- Change the "[name]" to "app" or whatever it is that your script asks for. 
TehEbil commented 3 years ago

@arkokoley thank you for your answer, but it changes after every build for us, do you have an advise?

nicholaszuccarelli commented 3 years ago

This is the same with me too. My worker file changes every time.

TehEbil commented 3 years ago

Does someone have another idea?

arkokoley commented 3 years ago

@TehEbil @nicholaszuccarelli Add this to your App.vue or main.js

  /* eslint-disable */
  var pdfwoker = require('worker-loader!pdfjs-dist/build/pdf.worker')
  /* eslint-enable */