Using parcel with its API generate Error: Cannot add a worker call if workerfarm is ending. errors randomly at build step, which trash the terminal with errors
Parcel should build without throwing this error
Parcel build and randomly throw(but still work as expected)
(node:30168) UnhandledPromiseRejectionWarning: Error: Cannot add a worker call if workerfarm is ending.
at WorkerFarm.addCall (C:\Users\Banou\Desktop\epk\node_modules\@parcel\workers\src\WorkerFarm.js:194:13)
at WorkerFarm.args [as run] (C:\Users\Banou\Desktop\epk\node_modules\@parcel\workers\src\WorkerFarm.js:77:21)
at Bundler.loadAsset (C:\Users\Banou\Desktop\epk\node_modules\parcel-bundler\src\Bundler.js:556:35)
(node:30168) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated
either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:30168) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit
Remove this throw since parcel still bundle correctly anyways
https://github.com/parcel-bundler/parcel/blob/master/packages/core/workers/src/WorkerFarm.js#L194
I'm using parcel as the main library to build around a 'no config' like testing library but having errors thrown like that is kind of annoying, especially since everything still work as expected.
You can yarn run dev and run the vscode debugging command.
Then try changing the source code of EPK(whatever file) quickly enough in a repeating manner, let the vscode nodemon debug launch the process and wait until the bundling starts. There is a chance that the error is thrown.
https://github.com/Banou26/epk
(I'm currently trying to setup a minimal repo demonstrating this error but i'm having trouble reproducing the error outside of EPK)
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.11
| Node |
| npm/Yarn |
| Operating System |
I managed to reproduce the error in a minimal repo https://github.com/Banou26/parcel-bug-2838
Run yarn run watch, exit, and run yarn run start to get the error, if it doesn't throw, exit and rerun the start script
I got the same issue when executing multiple bundler.bundle.
I avoid the error by calling the next bundle after bundled event:
bundlers.forEach(async (bundler) => {
await new Promise(resolve => {
bundler.on('bundled', resolve)
bundler.bundle()
})
})
I'm not sure if we are expected to use multiple bundlers in such way(if so, it would be good to document it) or there is something needs to be fine tuned in WorkerFarm.js
This kinda makes sense the workerfarm will exit if the bundler is finished.
So the first bundler will finish and stop the workerfarm while the second bundler still needs it. So it throws an error.
Not sure if this should be fixed as multiple bundlers will no longer be necessary in Parcel 2 as there will be multiple targets. For a workaround do what @hankchiutw proposed as that should fix it.
Would be glad to know if this is something we should still look into fixing for Parcel 1 or that the workaround is sufficient for you? There are other issues related to running multiple bundlers that do not throw errors but are actually just as bad. (overwriting of config when running bundlers in parallel is the most significant one.) So even if this is fixed it would still cause issues that just don't throw errors (most of the time)
It's all good, like i said, everything still work as expected, if i ever need to run multiple bundles, i'll use that workaround so there's no need to try and fix it especially since there's a multitude of problems like that, thanks @hankchiutw for the workaround.
Hyped for Parcel 2 馃敟
I also have this issue when require project other from node_modules while compiling my local directory parcel-bundler.
Do you know guys some workaround?
The proposed fix only works in the case of manually invoking the bundle method. When using the middleware there's no control over what gets executed when and therefore it fails.
Consider the following example:
const Bundler = require('parcel-bundler')
const express = require('express')
const app = express()
const app1 = new Bundler('./app1/index.html', { publicPath: '/app1', outDir: './dist-app1', cache: false })
const app2 = new Bundler('./app2/index.html', { publicPath: '/app2', outDir: './dist-app2', cache: false })
app.use('/app1', app1.middleware())
app.use('/app2', app2.middleware())
app.listen(8080)
Is there any way to get it to work? As you can see I have set separate folders for the bundlers to work with and disabled caching so that the .cache folder would not be a problem. However still the message about workers persists. Strangly enough sometimes it works (I assume there might be some kind of delay from wherever) but 99% of the time it doesn't.
@padcom I dont think there's any way to fix this, and Parcel 1 probably won't get a fix for this, i guess you could try using Parcel 2's alpha, but i'm not sure if you'll be able to use the API in a stable way.
@hankchiutw I want to thank you for your solution. Saved me a ton of time.
Most helpful comment
I got the same issue when executing multiple
bundler.bundle.I avoid the error by calling the next
bundleafterbundledevent:I'm not sure if we are expected to use multiple bundlers in such way(if so, it would be good to document it) or there is something needs to be fine tuned in
WorkerFarm.js