You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nuxt项目中关闭.eslintrc.js的no-console规则后console.log仍无法生效的求助

Troubleshooting console.log being blocked in your Nuxt app

Hey there! I see you've set { "no-console": "off" } in your .eslintrc.js but console.log is still not working. Let's break down the possible issues and fixes for this:

1. Double-check your ESLint config structure

First, make sure your .eslintrc.js is properly structured with the rule nested inside the rules object—missing this wrapper can cause the rule to fail silently:

module.exports = {
  // Your other ESLint settings (extends, parser, env, etc.)
  rules: {
    "no-console": "off"
  }
}

2. Explicitly configure the @nuxtjs/eslint-module

Since you're using @nuxtjs/eslint-module in your buildModules, the module might be overriding or ignoring your standalone .eslintrc.js config. Force the rule directly in the module's setup within nuxt.config.js to ensure it takes priority:

buildModules: [
  // Update the eslint-module entry like this
  ['@nuxtjs/eslint-module', {
    overrideConfig: {
      rules: {
        'no-console': 'off'
      }
    }
  }],
  "@nuxtjs/composition-api/module",
],

3. Disable console stripping in production builds

If you're testing in production mode, Nuxt's default Terser plugin automatically removes console statements to optimize bundle size. To preserve logs, add a terser configuration to your build block:

build: {
  transpile: ["vuex-stores"],
  loaders: {
    scss: {
      sourceMap: true,
      implementation: require("sass"),
      additionalData: `@import "~@/assets/scss/_bulma_variables.scss"; @import "~@/assets/scss/variables.scss";`,
    },
  },
  // Add this to keep console statements in production
  terser: {
    terserOptions: {
      compress: {
        drop_console: false
      }
    }
  }
},

Quick validation step

After making these changes, restart your dev server with npm run dev or rebuild and start production mode with npm run build && npm run start, then test your console.log statements again.

内容的提问来源于stack exchange,提问作者Čamo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 10:24:06