Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix errors for MultiCompilers build #78

Merged
merged 1 commit into from
May 31, 2017

Conversation

rkostrzewski
Copy link
Contributor

@rkostrzewski rkostrzewski commented May 30, 2017

When running webpack in MultiCompile mode (aka using more than one config) & one of configs uses SWPrecacheWebpackPlugin

const compiler = webpack([config1, config2])
compiler.run(...)

an error occurs, saying that callback has already been called:

/Users/rkostrzewski/GitHub/preact-cli/node_modules/async/dist/async.js:903
        if (fn === null) throw new Error("Callback was already called.");
                         ^

Error: Callback was already called.
    at /Users/rkostrzewski/GitHub/preact-cli/node_modules/async/dist/async.js:903:32
    at /Users/rkostrzewski/GitHub/preact-cli/node_modules/async/dist/async.js:1071:13
    at runCompilers (/Users/rkostrzewski/GitHub/preact-cli/node_modules/webpack/lib/MultiCompiler.js:102:46)
    at /Users/rkostrzewski/GitHub/preact-cli/node_modules/webpack/lib/MultiCompiler.js:107:5
    at /Users/rkostrzewski/GitHub/preact-cli/node_modules/webpack/lib/MultiCompiler.js:163:4
    at /Users/rkostrzewski/GitHub/preact-cli/node_modules/webpack/lib/Compiler.js:272:15
    at Compiler.emitRecords (/Users/rkostrzewski/GitHub/preact-cli/node_modules/webpack/lib/Compiler.js:367:37)
    at /Users/rkostrzewski/GitHub/preact-cli/node_modules/webpack/lib/Compiler.js:265:12
    at /Users/rkostrzewski/GitHub/preact-cli/node_modules/webpack/lib/Compiler.js:360:11
    at next (/Users/rkostrzewski/GitHub/preact-cli/node_modules/tapable/lib/Tapable.js:154:11)
    at /Users/rkostrzewski/GitHub/preact-cli/node_modules/graceful-fs/graceful-fs.js:43:10
    at FSReqWrap.oncomplete (fs.js:114:15)

This is because SWPrecacheWebpackPlugin incorrectly informs webpack that is has finished and calls webpack callback more than one time - this PR fixes that 🎉

plugin.configure(compiler, compilation);
callback();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I'm understanding - each compiler must inform that it has ended by calling callback.

Without this await runCompiler hungs because this plugin never called callback to indicate it has finished . This previously worked because SWPrecacheWebpackPlugin has been calling callback two times and webpack has seen that there are no callbacks that have not been called and after-emit phase has finished.

@goldhand
Copy link
Owner

Wow, good find! I need to spend more time reviewing this but I'm excited, this could fix #74

@hulkish
Copy link
Contributor

hulkish commented May 30, 2017

@goldhand from what i was able to see, this looks like the cause of our "duplicate output" issue. Good catch @rkostrzewski!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants