question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Absolute path for worker.js

See original GitHub issue

While the pdf viewer works well in local, I have an issue when building my application and serving it over IIS via an Asp.Net application. For some reason it tries to retrieve worker.js as an absolute path (/) while it should be relative : it tries to retrieve http://server-name/hash.worker.js instead of http://server-name/application-name/hash.worker.js

/3bc5b590ef81019703f0.worker.js
Failed to load resource: the server responded with a status of 404 (Not Found)

Note : when building I get this structure :

wwwroot
| - [hash].worker.js
| - static
    | - js
        | - 0.[hash].js
        | - app.[hash].js
        | - manifest.[hash].js
        | - vendor.[hash].js

It seems like worker.js is almost equivalent to 0.js (almost the same size for the .js, .js.gz and .js.map, just slighly lighter for the 0.js files). But including it won’t change anything, it still doesn’t work.

EDIT : I guess this is a webpack issue, but I don’t understand why it is served under the “publicPath” repository and not the usual directory used by everything else. The actual question is : Why is worker.js generated under the public path rather than the dist path ? And why is it not integrated in the vendor.js bundle ?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
FranckFreiburgercommented, Jan 25, 2019

worker-loader publicPath Type: String Default: null

Overrides the path from which worker scripts are downloaded. If not specified, the same public path used for other webpack assets is used.

// webpack.config.js
{
  loader: 'worker-loader'
  options: { publicPath: '/scripts/workers/' }
}

then try to hack this line: https://github.com/FranckFreiburger/vue-pdf/blob/fb274cbb81956d8c39f6febb67a2c11b72b1324d/src/vuePdfNoSss.vue#L13

1reaction
xuqihuacommented, Mar 19, 2020

I fixed it like this import PdfjsWorker from 'pdfjs-dist/build/pdf.worker.js'; webpack.config module : { rules: [ { test: /\.worker\.js$/, use : { loader : 'worker-loader', options: {inline: true, fallback: false} }, } ] }

Read more comments on GitHub >

github_iconTop Results From Across the Web

Javascript not resolving worker path relative to current script
I was under the impression that worker paths were resolved relative to the script spawning the worker, so shouldn't I just be able...
Read more >
The worker script filename must be an absolute path ... - GitHub
I'm trying to compile .js into 1 .exe file using nexe then can't run with your current code.
Read more >
Using Web Workers - Web APIs - MDN Web Docs
A worker is an object created using a constructor (e.g. Worker() ) that runs a named JavaScript file — this file contains the...
Read more >
jest-worker - npm
The module works by providing an absolute path of the module to be ... jest-worker will use child_process threads to spawn new Node.js...
Read more >
Relative URIs in Web Development - zzz.buzz
importScripts() is a method of WorkerGlobalScope interface for synchronously imports one or more scripts into the worker's scope. It accepts a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found