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

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

Open
ilyvion opened this issue Jul 5, 2020 · 2 comments · May be fixed by #97
Open

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

ilyvion opened this issue Jul 5, 2020 · 2 comments · May be fixed by #97

Comments

@ilyvion
Copy link

ilyvion commented Jul 5, 2020

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.
@bates64 bates64 linked a pull request Nov 26, 2020 that will close this issue
@ttencate
Copy link

ttencate commented Jun 22, 2021

Possibly related: if I use Webpack to build both the WASM and some TypeScript that depends on this WASM, then compilation of the TypeScript code proceeds even if compiling the Rust code failed (and might also subsequently fail if the bindings' API changed).

Edit: probably unrelated, because the PR by @nanaian above doesn't fix it. #47 is probably closer to what I was talking about.

@clairvoy
Copy link

clairvoy commented Oct 30, 2024

I'm running into the same issue, #97 fixes the issue, any chance to pick this fix for next release?

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 a pull request may close this issue.

3 participants