josdejong/workerpool

Syntax error on build following the webpack5 example

Stigjb opened this issue · 2 comments

We have a heavy workload we wanted to offload to web workers. workerpool looked like a good option due to the ability to add timeouts to tasks - we depend on third party libraries that leave us little control over resource usage.

I have based our setup on the webpack5 example in this repo (link), which uses worker-url and worker-url/plugin. The worker pool has been working well on the dev server, but building the package fails with the following error:

export function WorkerUrl(url, options) {
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:360:18)
    ...

Our app is built on Next.js, which itself uses Webpack. So as far as I know, configuration-wise, we should follow the Webpack example. However, the worker-url package used in the example looks abandoned, with the newest release being from 2021 and the NPM package having fewer than 1000 downloads a month. Is there a better exampe for us to look at?

Possibly related to #189 - even though I haven't seen anyone post issues with an identical SyntaxError.

I was able to get rid of the SyntaxError by using next-compose-plugins and next-transpile-modules as suggested in an old issue I found in the Next repo link. However, the project is still not building, but now there is a different error message: Error: Host domain missing:

Edit: It was an internal error I had run into - the next-transpile-modules approach may have been sufficient.

Thanks for reporting and sharing your solution. I tried out the webpack5 example, that works fine as far as I can see (it doesn't involve Next.js).