vue-cli: vue cli eslint no-console error when no prod mode

Version

3.0.0-rc.3

Reproduction link

https://github.com/acgotaku/vue-cli-issue

Node and OS info

yarn 1.9.4 node 8.11.3 Archlinux

Steps to reproduce

First , clone repo and run yarn serve command to start project. after, uncomment https://github.com/acgotaku/vue-cli-issue/blob/master/src/components/HelloWorld.vue#L35 console.log(msg) the terminal will output error: Unexpected console statement (no-console)

But if you stop yarn serve command and run again, the eslint error will disappear.

What is expected?

Only production mode output on console eslint error.

What is actually happening?

Add console.log to file will trigger eslint error. But if you rerun the command,the eslint error will disappear.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 19 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Make this modification to your package.json file, under “eslintConfig”:

...
    "rules": {
        "no-console": "off"
    },
...

You need to restart “npm run serve” in order for it to honor your new change.

Lazy quickfix for those who don’t want to tamper with anything: just use window.console.log

Is this still unresolved. I have this issue and can’t find a good workaround. Tried to set lintOnSave: 'error' in vue.config.js and the following in the eslintrc.js (and I tried the same thing with JSON format in eslintrc):

module.exports = {
  "extends": "eslint:recommended",
  "rules": {
    "no-console": "error",
  }
}

I thought this might force vue to inspect it. But inspection only happens on files that I actually change since the last npm run serve. So if it is cache related, is there a way (manually or in config) to clear the cache so that a npm run serve triggers recompilation and eslint checking of all files?

The error is shown because it is in the eslint:recommended ruleset & you imported it in your ESLint configuration https://github.com/eslint/eslint/blob/a857cd914200c56203a40a42dfbd69d9fe8dc351/conf/eslint-recommended.js#L97

If you want to distinguish production env for ESLint rules, please choose “placing config in dedicated config files” as such rule is only possible in a .js config file:

'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',

vue.config.js

const TerserPlugin = require('terser-webpack-plugin')
const isProd = process.env.NODE_ENV === 'production'
module.exports = {
  configureWebpack: {
    optimization: {
      minimize: true,
      minimizer: isProd ? [
        new TerserPlugin({
          terserOptions: {
            ecma: 6,
            compress: { drop_console: true },
            output: { comments: false, beautify: false }
          }
        })
      ] : []
    }
  }
}

Emphasizing @mzoe1330 last line… You need to restart “npm run serve” in order for it to honor your new change.

// eslint-disable-next-line no-console console.log()

Lazy quickfix for those who don’t want to tamper with anything: just use window.console.log

Works perfectly

That’s weird.

I believe it’s a bug in vue-loader used in combination with cache-loader. Will open an issue in the upstream library once I figure out a minimum reproduction.