{"action":"created","issue":{"url":"https://api.github.com/repos/mozilla/pdf.js/issues/7612","repository_url":"https://api.github.com/repos/mozilla/pdf.js","labels_url":"https://api.github.com/repos/mozilla/pdf.js/issues/7612/labels{/name}","comments_url":"https://api.github.com/repos/mozilla/pdf.js/issues/7612/comments","events_url":"https://api.github.com/repos/mozilla/pdf.js/issues/7612/events","html_url":"https://github.com/mozilla/pdf.js/issues/7612","id":175590783,"number":7612,"title":"Webpack instructions still cause 'fake worker' to load","user":{"login":"agilgur5","id":4970083,"avatar_url":"https://avatars.githubusercontent.com/u/4970083?v=3","gravatar_id":"","url":"https://api.github.com/users/agilgur5","html_url":"https://github.com/agilgur5","followers_url":"https://api.github.com/users/agilgur5/followers","following_url":"https://api.github.com/users/agilgur5/following{/other_user}","gists_url":"https://api.github.com/users/agilgur5/gists{/gist_id}","starred_url":"https://api.github.com/users/agilgur5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agilgur5/subscriptions","organizations_url":"https://api.github.com/users/agilgur5/orgs","repos_url":"https://api.github.com/users/agilgur5/repos","events_url":"https://api.github.com/users/agilgur5/events{/privacy}","received_events_url":"https://api.github.com/users/agilgur5/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mozilla/pdf.js/labels/1-other","name":"1-other","color":"DDDDDD"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-09-07T19:56:18Z","updated_at":"2016-09-09T20:39:09Z","closed_at":null,"body":"Configuration:\r\n- Web browser and its version: Chrome 52\r\n- Operating system and its version: OS X Yosemite\r\n- PDF.js version: 1.4.237\r\n- Is an extension: No\r\n\r\nSteps to reproduce the problem:\r\nMy code is:\r\n```\r\nimport pdflib from 'pdfjs-dist'\r\npdflib.PDFJS.workerSrc = './node_modules/pdfjs-dist/build/pdf.worker.entry.js'\r\n```\r\n\r\nexactly as described in https://github.com/mozilla/pdf.js/wiki/Setup-pdf.js-in-a-website#with-webpack,\r\nyet I get a `Warning: Setting up fake worker.'` in my console when I actually load a document, which makes it seem like the instructions did not work.  \r\n\r\n<br />\r\nAdditionally the wording on the instructions seems wrong as \"PDFJS.workerSrc _shall_ be set to point to this file\" (the current wording) means that it's automatically set, whereas \"PDFJS.workerSrc _should_ be set to point to this file\" means you have to set it yourself.\r\nThe [example code](https://github.com/mozilla/pdf.js/tree/master/examples/webpack) also isn't extremely helpful as it uses the relative paths into the repository (`pdfjsLib.PDFJS.workerSrc = '../../build/webpack/pdf.worker.bundle.js';`) that a person importing PDFJS would obviously not be able to do (not a very useful example).\r\n\r\n<br />\r\nI'm also confused as I searched through issues/PRs that are < 1 year old like https://github.com/mozilla/pdf.js/pull/6595 that do some automatic loading of the worker script, but that code seems to no longer exist in the repo, so both setting and not setting the `workerSrc` cause the fake worker to load for me... The fake worker knows where to find the worker script built by webpack (e.g. `1.bundle.js` is the worker when `bundle.js` is the script), so I'm confused why a real worker couldn't use this logic as well.\r\nI've tried pointing `workerSrc` to the `1.bundle.js` file created and even using webpack's [worker-loader](https://github.com/webpack/worker-loader) to instantiate and replace `PDFWorker` (`pdflib.PDFJS.PDFWorker = require('worker!pdfjs-dist/build/pdf.worker.entry.js')`), but that didn't work either, so I'm completely lost as to how the worker is supposed to work with webpack"},"comment":{"url":"https://api.github.com/repos/mozilla/pdf.js/issues/comments/246033113","html_url":"https://github.com/mozilla/pdf.js/issues/7612#issuecomment-246033113","issue_url":"https://api.github.com/repos/mozilla/pdf.js/issues/7612","id":246033113,"user":{"login":"agilgur5","id":4970083,"avatar_url":"https://avatars.githubusercontent.com/u/4970083?v=3","gravatar_id":"","url":"https://api.github.com/users/agilgur5","html_url":"https://github.com/agilgur5","followers_url":"https://api.github.com/users/agilgur5/followers","following_url":"https://api.github.com/users/agilgur5/following{/other_user}","gists_url":"https://api.github.com/users/agilgur5/gists{/gist_id}","starred_url":"https://api.github.com/users/agilgur5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/agilgur5/subscriptions","organizations_url":"https://api.github.com/users/agilgur5/orgs","repos_url":"https://api.github.com/users/agilgur5/repos","events_url":"https://api.github.com/users/agilgur5/events{/privacy}","received_events_url":"https://api.github.com/users/agilgur5/received_events","type":"User","site_admin":false},"created_at":"2016-09-09T20:39:09Z","updated_at":"2016-09-09T20:39:09Z","body":"> Yes, I tried that at #6785, later at #6791 and then reverted that. Having require('worker!... causes issue in browserify, and require('webworkerify')(...) in webpack.\r\n\r\nBut wouldn't your `__webpack_require__` check here\r\nhttps://github.com/mozilla/pdf.js/pull/6785/commits/79c2f69c3288494c5ce2809182c896484bf4be5c#diff-5f93a8d6c23cf0a169c6ee7347477ce8R30  prevent browserify from parsing that statement? (not sure if the `ensure` part was causing problems)\r\n\r\n> Yes, working PR will really good to have. So far pdfjs-dist somehow works with webpack, browserify along with system.js and node.js; and we will try to keep it this way. Thanks.\r\n\r\nI'll probably get to this later next week -- is there a test to run to check against various bundlers/platforms?\r\n\r\n>  I was planning to add overloaded constructor for PDFWorker that would accept an web worker is a parameter -- this might provide the alternative solution for some webpack/browserify usecases.\r\n\r\nI think this would be a fantastic alternative! Specifically, if it could accept a `Worker` class, then webpack folks could use something like: [webworkerify-webpack](https://github.com/borisirota/webworkify-webpack) and browserify folks just use the [webworkerify](https://github.com/substack/webworkify) and just pass the loader/Worker as an argument. So it would be `var worker = new WorkerFromArgs('../pdf.worker.entry.js')` in the overloaded case.\r\nThis would offload the configuration of worker loaders logic into user-land so potentially messy PRs that check for platform/bundler into pdf.js aren't necessary"}}
{"actor":{"display_login":"agilgur5"}}