Nuxt项目中关闭.eslintrc.js的no-console规则后console.log仍无法生效的求助
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

