Skip to content

wasm-pack build error not correctly propagated to webpack #90

@ilyvion

Description

@ilyvion

If the call to wasm-pack build fails, yarn (which runs webpack --mode production) still returns an error code of 0. I traced the problem to this bit of code:

compiler.hooks.thisCompilation.tap('WasmPackPlugin', (compilation) => {
  // Super hacky, needed to workaround a bug in Webpack which causes
  // thisCompilation to be triggered twice on the first compilation.
  if (first) {
    first = false;

  } else {
    // This is needed in order to gracefully handle errors in Webpack,
    // since Webpack has its own custom error system.
    if (this.error != null) {
      compilation.errors.push(this.error);
    }
  }
});

Since first is true (at least in the cases I tested), the else branch never triggers, and so no error is reported back to webpack. By moving the

if (this.error != null) {
  compilation.errors.push(this.error);
}

bit into the if branch, I got the behavior I expected; i.e. the output from yarn is

ERROR in Rust compilation.
error Command failed with exit code 2.

instead of

Done in 1.66s.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions