Skip to content
This repository has been archived by the owner on Feb 7, 2022. It is now read-only.

parallel-webpack causes bundle-analyser create empty/broken stats file #85

Closed
byara opened this issue Sep 7, 2018 · 8 comments · May be fixed by #87
Closed

parallel-webpack causes bundle-analyser create empty/broken stats file #85

byara opened this issue Sep 7, 2018 · 8 comments · May be fixed by #87

Comments

@byara
Copy link
Contributor

byara commented Sep 7, 2018

Explain the problem

I'm using parallel-webpack and webpack-bundle-analyser and it seems that parallel-webpack is causing webpack-bundle-analyser stop creating the reports midway so I sometimes end up with the correctly made stats or sometimes empty or invalid json files.
Might be related to: webpack-contrib/webpack-bundle-analyzer#152 (comment)

Expected Behaviour

to let webpack-bundle-analyser finish creating the report

Actual Behaviour

stops webpack-bundle-analyser from creating the reports causing indeterministic behavior

Steps to reproduce

has to be done on a large codebase with about 10 or more builds in parallel.

Provide your webpack config

Provide your Environment details

  • Node version:
    8.11.3
  • Operating System:
    macOS High Sierra
  • webpack version:
    ^4.17.1
  • parallel-webpack version:
    ^2.3.0
@byara
Copy link
Contributor Author

byara commented Sep 7, 2018

I tried this with the both 3.0.0-alpha.1 and 3.0.0-alpha.2 and in both the reports are made but the json files are empty.

@frvge
Copy link

frvge commented Sep 9, 2018

Could it be because process.exit is sometimes used instead of process.exitCode?

@alexpavlovich
Copy link

UP, I have the same issue with 16 parallel builds. The one that builds last finishes all build process before webpack-bundle-analyzer starts so I miss bundle analysis report for that last built bundle.

@byara
Copy link
Contributor Author

byara commented Sep 10, 2018

@frvge I think that could help with the issue as recommended by documentation:

https://nodejs.org/api/process.html#process_process_exit_code

@liangchunn
Copy link

So, me and @byara found out that the processes are eagerly terminated without waiting for stuff like plugins to finish.

These particular lines in index.js caused the issue: https://github.com/trivago/parallel-webpack/blob/master/index.js#L141-L144

}).finally(function () {
    workerFarm.end(workers);
    process.removeListener('SIGINT', shutdownCallback);
});

Changing the lines to delay the killing of the workers made it possible for all (but not guaranteed) async operations to complete:

}).finally(function () {
    var __timeout = setTimeout(() => {
        clearTimeout(__timeout)
        workerFarm.end(workers);
        process.removeListener('SIGINT', shutdownCallback);
    }, 10000)
});

There must be a better way to detect when webpack has fully completed its job, then only exit. Maybe with some kind of compilation hook?

@liangchunn
Copy link

Update
I've pinned down the issue to webpack-bundle-analyzer and opened an issue here:
webpack-contrib/webpack-bundle-analyzer#232

@byara
Copy link
Contributor Author

byara commented Dec 8, 2018

I tried to apply what @liangchunn suggested here. Unfortunately, now the last reports are mostly "unfinished". It seems, if there was enough time and the stats file was small enough, they are created properly but if they are huge, webpack-bundle-analyzer makes stats files undone. As @liangchunn pointed out, with my changes, the reports are now made synchronously https://github.com/byara/webpack-bundle-analyzer/blob/master/src/BundleAnalyzerPlugin.js#L58-L69, so there must be other reasons to this behavior.

@byara
Copy link
Contributor Author

byara commented Dec 21, 2018

After the merge of the PR in v2.3.0 we have the option to pass --keep-alive-after-finish flag so parallel-webpack does not end the workers after the build is finished. This solves my problem, therefore I close the issue.

@byara byara closed this as completed Dec 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants