Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Webpack build fails even with failOnError: false #257

Closed
edmorley opened this issue Nov 19, 2018 · 2 comments
Closed

Webpack build fails even with failOnError: false #257

edmorley opened this issue Nov 19, 2018 · 2 comments

Comments

@edmorley
Copy link
Contributor

Hi

The docs for the failOnError option say:

failOnError (default: false)
Loader will cause the module build to fail if there are any eslint errors.

This gives the impression that any ESLint errors will not cause the build to fail out of the box.

However this is not the case. eg:

  1. Clone https://github.com/edmorley/testcase-eslint-loader-failOnError
  2. yarn
  3. yarn webpack --mode development

Expected:
Exit code of zero.

Actual:

$ yarn webpack --mode development
...
Hash: 9d62ea16c01b405cadff
Version: webpack 4.26.0
Time: 693ms
Built at: 11/19/2018 1:24:58 PM
  Asset     Size  Chunks             Chunk Names
main.js  3.8 KiB    main  [emitted]  main
Entrypoint main = main.js
[./src/index.js] 33 bytes {main} [built] [1 error]

ERROR in ./src/index.js
Module Error (from ./node_modules/eslint-loader/index.js):

C:\Users\Ed\src\testcase-eslint-loader-failOnError\src\index.js
  2:5  error  'a' is defined but never used  no-unused-vars

✖ 1 problem (1 error, 0 warnings)

error Command failed with exit code 2.

The only way to get an exit code of zero is to set emitWarning: true.

It looks like webpack's emitError now causes the compile to fail (perhaps it didn't in older webpack?), here:

emitter(new ESLintError(messages));

This behaviour may actually be the intended behaviour, however if so:

  1. it would be good to update the eslint-loader docs to make it clearer
  2. it then seems that the failOnError option is actually redundant and could be removed? (since unlike failOnWarning, it's unable to actually override webpack's handling here)
@rocspring
Copy link

thx. I'm also confused by the problem

@radcapitalist
Copy link

Here is what I just realized is the difference: Yes, npm will exit with code 2 regardless of how failOnError or failOnWarning are set. However, it does affect whether the module is marked as failing to build in the built bundle. If you have failOnError and failOnWarning both set to false, and you build and you have eslint errors and warnings, you will still be able to run your build. OTOH, if failOnError is true and you have eslint errors, the module will be marked as having failed to build in the built bundle, and the bundle will not run.

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

No branches or pull requests

4 participants