Skip to content

Cannot find module worker-loader!./pdf.worker.entry.js when using entry.webpack and Mocha #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
haf opened this issue Sep 11, 2018 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@haf
Copy link

haf commented Sep 11, 2018

Testing v4-beta.4 w/ Babel 7 w/ Mocha and this import:

import { Document, Page } from 'react-pdf/dist/entry.webpack';

Crashes like so:

Error: Cannot find module 'worker-loader!./pdf.worker.entry.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/root/node_modules/react-pdf/dist/entry.webpack.js:24:23)
    at Module._compile (module.js:652:30)
    at Module._compile (/root/node_modules/pirates/lib/index.js:83:24)
    at Module._extensions..js (module.js:663:10)
    at Object.newLoader [as .js] (/root/node_modules/pirates/lib/index.js:88:7)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/root/app/expenses/components/Documents/PDFDocument.js:4:1)

The workaround with dist/no.worker doesn't work anymore, because that file doesn't exist in beta.4 and I haven't got worker-loader installed; is it required from now on? I can compile and run the app normally without installing it; only mocha has issues.

$ cat yarn.lock | grep webpack
"@webpack-contrib/config-loader@^1.2.0":
  resolved "https://registry.yarnpkg.com/@webpack-contrib/config-loader/-/config-loader-1.2.1.tgz#5b3dd474e207437939d294d200c68b7b00008e04"
    "@webpack-contrib/schema-utils" "^1.0.0-beta.0"
    webpack-log "^1.1.2"
"@webpack-contrib/schema-utils@^1.0.0-beta.0":
  resolved "https://registry.yarnpkg.com/@webpack-contrib/schema-utils/-/schema-utils-1.0.0-beta.0.tgz#bf9638c9464d177b48209e84209e23bee2eb4f65"
    webpack-log "^1.1.2"
babel-plugin-webpack-alias@^2.1.2:
  resolved "https://registry.yarnpkg.com/babel-plugin-webpack-alias/-/babel-plugin-webpack-alias-2.1.2.tgz#05a1ba23c28595660fb6ea5736424fc596b4a247"
clean-webpack-plugin@^0.1.19:
  resolved "https://registry.yarnpkg.com/clean-webpack-plugin/-/clean-webpack-plugin-0.1.19.tgz#ceda8bb96b00fe168e9b080272960d20fdcadd6d"
compression-webpack-plugin@^2.0.0:
  resolved "https://registry.yarnpkg.com/compression-webpack-plugin/-/compression-webpack-plugin-2.0.0.tgz#46476350c1eb27f783dccc79ac2f709baa2cffbc"
    webpack-sources "^1.0.1"
copy-webpack-plugin@^4.5.2:
  resolved "https://registry.yarnpkg.com/copy-webpack-plugin/-/copy-webpack-plugin-4.5.2.tgz#d53444a8fea2912d806e78937390ddd7e632ee5c"
html-webpack-plugin@^3.2.0:
  resolved "http://registry.npmjs.org/html-webpack-plugin/-/html-webpack-plugin-3.2.0.tgz#b01abbd723acaaa7b37b6af4492ebda03d9dd37b"
last-call-webpack-plugin@^3.0.0:
  resolved "https://registry.yarnpkg.com/last-call-webpack-plugin/-/last-call-webpack-plugin-3.0.0.tgz#9742df0e10e3cf46e5c0381c2de90d3a7a2d7555"
    webpack-sources "^1.1.0"
    webpack-sources "^1.1.0"
optimize-css-assets-webpack-plugin@^5.0.1:
  resolved "https://registry.yarnpkg.com/optimize-css-assets-webpack-plugin/-/optimize-css-assets-webpack-plugin-5.0.1.tgz#9eb500711d35165b45e7fd60ba2df40cb3eb9159"
    last-call-webpack-plugin "^3.0.0"
uglifyjs-webpack-plugin@^1.2.4:
  resolved "https://registry.yarnpkg.com/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-1.3.0.tgz#75f548160858163a08643e086d5fefe18a5d67de"
    webpack-sources "^1.1.0"
webpack-bundle-analyzer@^2.13.1:
  resolved "https://registry.yarnpkg.com/webpack-bundle-analyzer/-/webpack-bundle-analyzer-2.13.1.tgz#07d2176c6e86c3cdce4c23e56fae2a7b6b4ad526"
webpack-command@^0.4.1:
  resolved "https://registry.yarnpkg.com/webpack-command/-/webpack-command-0.4.1.tgz#3f88aae87c28292ed0a97293615a2e962a1c66f4"
    "@webpack-contrib/config-loader" "^1.2.0"
    "@webpack-contrib/schema-utils" "^1.0.0-beta.0"
    webpack-log "^1.1.2"
[email protected]:
  resolved "https://registry.yarnpkg.com/webpack-dev-middleware/-/webpack-dev-middleware-3.2.0.tgz#a20ceef194873710052da678f3c6ee0aeed92552"
    webpack-log "^2.0.0"
webpack-dev-server@^3.1.8:
  resolved "https://registry.yarnpkg.com/webpack-dev-server/-/webpack-dev-server-3.1.8.tgz#eb7a95945d1108170f902604fb3b939533d9daeb"
    webpack-dev-middleware "3.2.0"
    webpack-log "^2.0.0"
webpack-log@^1.1.2:
  resolved "https://registry.yarnpkg.com/webpack-log/-/webpack-log-1.2.0.tgz#a4b34cda6b22b518dbb0ab32e567962d5c72a43d"
webpack-log@^2.0.0:
  resolved "https://registry.yarnpkg.com/webpack-log/-/webpack-log-2.0.0.tgz#5b7928e0637593f119d32f6227c1e0ac31e1b47f"
webpack-merge@^4.1.4:
  resolved "https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-4.1.4.tgz#0fde38eabf2d5fd85251c24a5a8c48f8a3f4eb7b"
webpack-sources@^1.0.1, webpack-sources@^1.1.0, webpack-sources@^1.2.0:
  resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.2.0.tgz#18181e0d013fce096faf6f8e6d41eeffffdceac2"
webpack@^4.17.2:
  resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.17.2.tgz#49feb20205bd15f0a5f1fe0a12097d5d9931878d"
    uglifyjs-webpack-plugin "^1.2.4"
    webpack-sources "^1.2.0"

pdfjs-dist@^2.0.550:
  resolved "https://registry.yarnpkg.com/pdfjs-dist/-/pdfjs-dist-2.0.550.tgz#52a5bd05d8b250206ccd2843209cfa3b8f1ea4ae"
react-pdf@^4.0.0-beta.4:
  resolved "https://registry.yarnpkg.com/react-pdf/-/react-pdf-4.0.0-beta.4.tgz#95fe7cd43a04b34cd26a07838334869e0460ba7d"
    pdfjs-dist "^2.0.550"

"@webpack-contrib/config-loader@^1.2.0":
  resolved "https://registry.yarnpkg.com/@webpack-contrib/config-loader/-/config-loader-1.2.1.tgz#5b3dd474e207437939d294d200c68b7b00008e04"
babel-loader@^8.0.0:
  resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-8.0.2.tgz#2079b8ec1628284a929241da3d90f5b3de2a5ae5"
    loader-utils "^1.0.2"
    loader-utils "^1.1.0"
css-loader@^1.0.0:
  resolved "https://registry.yarnpkg.com/css-loader/-/css-loader-1.0.0.tgz#9f46aaa5ca41dbe31860e3b62b8e23c42916bf56"
    loader-utils "^1.0.2"
eslint-loader@^2.1.0:
  resolved "https://registry.yarnpkg.com/eslint-loader/-/eslint-loader-2.1.0.tgz#61334c548aeb0b8e20ec3a552fb7a88c47261c6a"
    loader-fs-cache "^1.0.0"
    loader-utils "^1.0.2"
file-loader@^2.0.0:
  resolved "https://registry.yarnpkg.com/file-loader/-/file-loader-2.0.0.tgz#39749c82f020b9e85901dcff98e8004e6401cfde"
    loader-utils "^1.0.2"
    loader-utils "^0.2.16"
imports-loader@^0.8.0:
  resolved "https://registry.yarnpkg.com/imports-loader/-/imports-loader-0.8.0.tgz#030ea51b8ca05977c40a3abfd9b4088fe0be9a69"
    loader-utils "^1.0.2"
json-loader@^0.5.7:
  resolved "https://registry.yarnpkg.com/json-loader/-/json-loader-0.5.7.tgz#dca14a70235ff82f0ac9a3abeb60d337a365185d"
less-loader@^4.0.5:
  resolved "https://registry.yarnpkg.com/less-loader/-/less-loader-4.1.0.tgz#2c1352c5b09a4f84101490274fd51674de41363e"
    loader-utils "^1.1.0"
loader-fs-cache@^1.0.0:
  resolved "https://registry.yarnpkg.com/loader-fs-cache/-/loader-fs-cache-1.0.1.tgz#56e0bf08bd9708b26a765b68509840c8dec9fdbc"
loader-runner@^2.3.0:
  resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.3.0.tgz#f482aea82d543e07921700d5a46ef26fdac6b8a2"
loader-utils@^0.2.16:
  resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-0.2.17.tgz#f86e6374d43205a6e6c60e9196f17c0299bfb348"
loader-utils@^1.0.0, loader-utils@^1.0.2, loader-utils@^1.1.0:
  resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.1.0.tgz#c98aef488bcceda2ffb5e2de646d6a754429f5cd"
    loader-utils "^1.1.0"
    worker-loader "^2.0.0"
raw-loader@^0.5.1:
  resolved "https://registry.yarnpkg.com/raw-loader/-/raw-loader-0.5.1.tgz#0c3d0beaed8a01c966d9787bf778281252a979aa"
react-hot-loader@^4.3.6:
  resolved "https://registry.yarnpkg.com/react-hot-loader/-/react-hot-loader-4.3.6.tgz#26e1491f08daf2bad99d141b1927c9faadef2fb4"
source-map-loader@^0.2.3:
  resolved "https://registry.yarnpkg.com/source-map-loader/-/source-map-loader-0.2.4.tgz#c18b0dc6e23bf66f6792437557c569a11e072271"
    loader-utils "^1.1.0"
style-loader@^0.23.0:
  resolved "https://registry.yarnpkg.com/style-loader/-/style-loader-0.23.0.tgz#8377fefab68416a2e05f1cabd8c3a3acfcce74f1"
    loader-utils "^1.1.0"
stylus-loader@^3.0.2:
  resolved "https://registry.yarnpkg.com/stylus-loader/-/stylus-loader-3.0.2.tgz#27a706420b05a38e038e7cacb153578d450513c6"
    loader-utils "^1.0.2"
url-loader@^1.1.1:
  resolved "https://registry.yarnpkg.com/url-loader/-/url-loader-1.1.1.tgz#4d1f3b4f90dde89f02c008e662d604d7511167c1"
    loader-utils "^1.1.0"
    "@webpack-contrib/config-loader" "^1.2.0"
    loader-utils "^1.1.0"
    loader-runner "^2.3.0"
    loader-utils "^1.1.0"
worker-loader@^2.0.0:
  resolved "https://registry.yarnpkg.com/worker-loader/-/worker-loader-2.0.0.tgz#45fda3ef76aca815771a89107399ee4119b430ac"
    loader-utils "^1.0.0"

@wojtekmaj wojtekmaj self-assigned this Sep 13, 2018
@wojtekmaj wojtekmaj added the question Further information is requested label Sep 13, 2018
@wojtekmaj
Copy link
Owner

wojtekmaj commented Sep 13, 2018

Okay, here's the deal. loader-name-goes-here!./path/goes/here syntax is Webpack only (loaders are a Webpack thing after all - so to answer your question is worker-loader needed now - no). For tests, you're supposed to use normal entry file.

For Jest, you can use this solution.

Regarding Mocha, I need to ask the community - is there a way to map module names so that they will be replaced on the fly in test environment, like in Jest?

Alternative solution would be to ditch entry.webpack for normal entry file (import { } from 'react-pdf'), but you will need to copy pdf.worker.js to your dist directory from node_modules/pdfjs-dist on your own, e.g. using CopyWebpackPlugin. This way Mocha would not get confused on Webpack syntax.

@wojtekmaj wojtekmaj changed the title v4-beta.4` w/ Babel 7 w/ Mocha fails to find 'pdf.worker.entry' Cannot find module worker-loader!./pdf.worker.entry.js when using entry.webpack and Mocha Sep 13, 2018
@varand-pez
Copy link

varand-pez commented Apr 30, 2019

Any solution to this? I'm stuck with the failing test...
"jsdom": "8.1.0",
"jsdom-global": "1.7.0",

@wojtekmaj
Copy link
Owner

wojtekmaj commented May 3, 2019

@varand-pez Newest Jest uses jsdom 11.5.1 so you're quite a bit behind. Nonetheless, it should work fine provided that you don't use webpack-specific entry point AND either you're not rendering canvas or have canvas support enabled.

@varand-pez
Copy link

varand-pez commented May 4, 2019

I dont understand what the issue is. is it webpack? is it old version of jsdom?
I'm not even using JEST, that's why I opened a new issue, I'm using MOCHA

@varand-pez
Copy link

And just to try things I upgraded packages to the latest but still failing on the same exact issue.

-    "jsdom": "8.1.0",
-    "jsdom-global": "1.7.0",
-    "mocha": "3.5.3",
+    "jsdom": "15.0.0",
+    "jsdom-global": "3.0.2",
+    "mocha": "6.1.4",

@daiyrbekov12

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants