Angular. Pdfjs-dist worker. Problem in deployed production enviroment

Discussão em 'Angular' iniciado por Raziel, Setembro 10, 2024.

  1. Raziel

    Raziel Guest

    I need to use pdf library pdfjs-dist. I set up worker like this:

    PDF.GlobalWorkerOptions.workerSrc = 'pdf.worker.mjs';


    and in angular.json like this:

    {
    "glob": "pdf.worker.*",
    "input": "node_modules/pdfjs-dist/legacy/build/",
    "output": ""
    },
    {
    "glob": "pdf.*",
    "input": "node_modules/pdfjs-dist/legacy/build/",
    "output": ""
    }


    The problem is that everything works locally but when the app is deployed setting up the worker fails and the file is blocked because of disallowed MIME „application/octet-stream".

    Update: I managed to get it working by copying the worker.min.js file into assets. And changing this:

    PDF.GlobalWorkerOptions.workerSrc = '/assets/pdf.worker.mjs';


    So I have another question. Is worker not included into bundle and that is why the problem is occuring? If so what is the appropriate solution.

    How can I make it work without copying the worker file into assets folder?

    Continue reading...

Compartilhe esta Página