Pdf.js: Error: Cannot find module 'worker-loader!./build/pdf.worker.js'

Created on 7 Jul 2019  ·  14Comments  ·  Source: mozilla/pdf.js

import pdfjs from "pdfjs-dist/webpack.js";

results in:

Error: Cannot find module 'worker-loader!./build/pdf.worker.js'

npm list webpack worker-loader pdfjs-dist

+-- [email protected] 
| `-- [email protected]  deduped
+-- [email protected] 
`-- [email protected] 

What could be a reason for that? The suggestion was:

You can use the pdfjs-dist/webpack module for PDF.js autoconfiguration.
:D

1-other

Most helpful comment

@timvandermeij
so, how we can use it now?
import pdfjs from "pdfjs-dist/webpack.js"; not works already.

All 14 comments

Same problem here
Is there anything I can do about in order to use pdf.js?

some problem with me.

info

parcel + vue + vue-pdf

❯ yarn list vue vue-pdf parcel-bounld
yarn list v1.17.3
warning Filtering by arguments is deprecated. Please use the pattern option instead.
├─ [email protected]
└─ [email protected]
✨  Done in 0.13s.

error

❯ yarn run dev
yarn run v1.17.3
$ parcel index.html
Server running at http://localhost:1234 
⠙ Building index.js...Browserslist: caniuse-lite is outdated. Please run next command `yarn upgrade caniuse-lite browserslist`
⠼ Building app.vue...Browserslist: caniuse-lite is outdated. Please run next command `yarn upgrade caniuse-lite browserslist`
🚨  /Users/pengliheng/work/src/github.com/pengliheng/6estates/node_modules/vue-pdf/src/vuePdfNoSss.vue:13:28: Cannot resolve dependency 'worker-loader!pdfj
s-dist/build/pdf.worker.js'
    at Resolver.resolve (/Users/pengliheng/.config/yarn/global/node_modules/parcel-bundler/src/Resolver.js:71:17)
    at async Bundler.resolveAsset (/Users/pengliheng/.config/yarn/global/node_modules/parcel-bundler/src/Bundler.js:433:18)
    at async Bundler.resolveDep (/Users/pengliheng/.config/yarn/global/node_modules/parcel-bundler/src/Bundler.js:484:14)
    at async /Users/pengliheng/.config/yarn/global/node_modules/parcel-bundler/src/Bundler.js:608:26
    at async Promise.all (index 6)
    at async Bundler.loadAsset (/Users/pengliheng/.config/yarn/global/node_modules/parcel-bundler/src/Bundler.js:599:21)
    at async /Users/pengliheng/.config/yarn/global/node_modules/parcel-bundler/src/Bundler.js:610:13
    at async Promise.all (index 1)
    at async Bundler.loadAsset (/Users/pengliheng/.config/yarn/global/node_modules/parcel-bundler/src/Bundler.js:599:21)
    at async /Users/pengliheng/.config/yarn/global/node_modules/parcel-bundler/src/Bundler.js:610:13
    at async Promise.all (index 2)
    at async Bundler.loadAsset (/Users/pengliheng/.config/yarn/global/node_modules/parcel-bundler/src/Bundler.js:599:21)
    at async /Users/pengliheng/.config/yarn/global/node_modules/parcel-bundler/src/Bundler.js:610:13
    at async Promise.all (index 0)
    at async Bundler.loadAsset (/Users/pengliheng/.config/yarn/global/node_modules/parcel-bundler/src/Bundler.js:599:21)
    at async Bundler.processAsset (/Users/pengliheng/.config/yarn/global/node_modules/parcel-bundler/src/Bundler.js:557:5)

Closing since we've changed the way we're working with Webpack to remove those dependencies from pdfjs-dist.

@timvandermeij
so, how we can use it now?
import pdfjs from "pdfjs-dist/webpack.js"; not works already.

@timvandermeij
so, how we can use it now?
import pdfjs from "pdfjs-dist/webpack.js"; not works already.

+1, having the same error here as I used to import pdfjs-dist/webpack, how this should be coded now?

Install worker-loader and try again:

npm install worker-loader --save-dev

Thanks, @tgbv I did, after that my build complained that I need module, installed that and then worked out for me, I'm still intrigued if that would be the best way to deal with this in the long run, since now my dependencies grew in more than a hundred packages more, and now my build produces the next warnings

warning in ./node_modules/lazy-debug-legacy/src/functions.js
Critical dependency: the request of a dependency is an expression
warning in ./node_modules/lazy-debug-legacy/src/functions.js
Critical dependency: the request of a dependency is an expression

that came after adding module to my package.json

@jsamayoap I am having the same issue, not sure what is causing it yet.

do we have a solution for this

I'm sorry I lost the track of this @jsamayoap, @jameseggers please attempt the following solution to avoid the warnings: https://stackoverflow.com/a/42924147

@yotavm try this: https://github.com/mozilla/pdf.js/issues/10952#issuecomment-639374815

I had the same issue. I think problem is where the bundler converts the string-based import to an ugly string.

my solution was to use like follows

issue code

import('pdfjs-dist/webpack')

solution

import(pdfjs-dist/webpack) 

Thanks @tgbv I've checked what you proposed on the SO link to no avail, in that case, they argue about a library called "request", but my issue is with another library, called "module", I've tried their solution, installing a fixed version of "request" and latest version of that same library, in both cases the compile produce the same reported warnings.

@rameezrami tried what you proposed but I import the library as:
import { getDocument, PDFLoadingTask, PDFDocumentProxy, PDFRenderParams } from 'pdfjs-dist/webpack';

Tried to replace that with this:
import { getDocument, PDFLoadingTask, PDFDocumentProxy, PDFRenderParams } from pdfjs-dist/webpack;

Then it simply didn't compile

After installing worker-loader as suggested by @tgbv I encounter an error:
_Invalid handler for event "error": got undefined
found in
---> at node_modules/vue-pdf/src/vuePdfNoSss.vue_

did anyone encounter an error like this?

Pls insert code into html page:
<base href="/">

Was this page helpful?
0 / 5 - 0 ratings

Related issues

azetutu picture azetutu  ·  4Comments

aaronshaf picture aaronshaf  ·  3Comments

BrennanDuffey picture BrennanDuffey  ·  3Comments

sujit-baniya picture sujit-baniya  ·  3Comments

brandonros picture brandonros  ·  3Comments