title: Looking for help to make npm/pdfjs-dist work with Webpack and Django
body: <p>I've been trying for a few hours replacing a link-based pdf.js with an npm install of <code>pdfjs-dist</code>, since I noticed that my links were not meant to be used as cdns and could become unstable as <a href="https://github.com/mozilla/pdf.js/issues/10997#issuecomment-513939192" rel="noreferrer">described here</a>.</p>
  <p>I could not find much documentation on how to make that work other than a few examples, and when Webpack is involved they are mostly with React, while I am simply using ES6 in a Django framework (static compiling on the desired django directory, without using the webpack-plugin.)</p>
  <p>After <a href="https://github.com/mozilla/pdf.js/issues/10838#issuecomment-678661860" rel="noreferrer">exchanging several messages</a> with one of the guys that work on pdf.js it seemed that my compiling errors were probably due to how Webpack handles internally the library. Here's what I am seeing:</p>
  <pre><code>WARNING in ./node_modules/worker-loader/dist/index.js
  Module not found: Error: Can't resolve 'webpack/lib/web/FetchCompileAsyncWasmPlugin' in '/home/giampaolo/dev/KJ_import/KJ-JS/node_modules/worker-loader/dist'
   @ ./node_modules/worker-loader/dist/index.js
   @ ./node_modules/worker-loader/dist/cjs.js
   @ ./node_modules/pdfjs-dist/webpack.js
   @ ./src/js/views/pdfViews.js
   @ ./src/js/index.js
  
  WARNING in ./node_modules/worker-loader/dist/index.js
  Module not found: Error: Can't resolve 'webpack/lib/web/FetchCompileWasmPlugin' in '/home/giampaolo/dev/KJ_import/KJ-JS/node_modules/worker-loader/dist'
   @ ./node_modules/worker-loader/dist/index.js
   @ ./node_modules/worker-loader/dist/cjs.js
   @ ./node_modules/pdfjs-dist/webpack.js
   @ ./src/js/views/pdfViews.js
   @ ./src/js/index.js
  
  ERROR in (webpack)/lib/node/NodeTargetPlugin.js
  Module not found: Error: Can't resolve 'module' in '/home/giampaolo/dev/KJ_import/KJ-JS/node_modules/webpack/lib/node'
   @ (webpack)/lib/node/NodeTargetPlugin.js 11:1-18
   @ ./node_modules/worker-loader/dist/index.js
   @ ./node_modules/worker-loader/dist/cjs.js
   @ ./node_modules/pdfjs-dist/webpack.js
   @ ./src/js/views/pdfViews.js
   @ ./src/js/index.js
  Child HtmlWebpackCompiler:
       1 asset
      Entrypoint HtmlWebpackPlugin_0 = __child-HtmlWebpackPlugin_0
      [./node_modules/html-webpack-plugin/lib/loader.js!./src/src-select.html] 4.57 KiB {HtmlWebpackPlugin_0} [built]
  Child worker-loader node_modules/pdfjs-dist/build/pdf.worker.js:
                Asset      Size      Chunks             Chunk Names
      index.worker.js  1.33 MiB  pdf.worker  [emitted]  pdf.worker
      Entrypoint pdf.worker = index.worker.js
      [./node_modules/pdfjs-dist/build/pdf.worker.js] 1.25 MiB {pdf.worker} [built]
      [./node_modules/process/browser.js] 5.29 KiB {pdf.worker} [built]
  ℹ ｢wdm｣: Failed to compile.
  </code></pre>
  <p>Theoretically the <code>pdfjs-dist</code> should come with a zero configuration file, without even needing to set up a worker for it, so code like the one below <em>should</em> work:</p>
  <pre><code>import pdfjsLib from 'pdfjs-dist/webpack'
  
  ////////////////////////////////////////////
  //// instantiate pdf
  export const pdfView = () =&gt; {
    // pdfjsLib.GlobalWorkerOptions.workerSrc = 'index.worker.js';
  
    // var defined through a Django template tag
    const loadingTask = pdfjsLib.getDocument(pdfData.myPdfDoc)
  
    pdfData.myPdf = loadingTask.promise.then(pdf =&gt; {
      pdfData.pdfTotalPageN = pdf.numPages;
      return pdf;
    })
  }
  
  </code></pre>
  <p>but it doesn't get compiled, and I would really appreciate some pointers.
  Thanks in advance</p>