{"id":20585,"library":"stylelint-webpack-plugin","title":"stylelint-webpack-plugin","description":"A webpack plugin that runs Stylelint during the build process to lint CSS, SCSS, SASS, and other style files. Current stable version is 5.1.0, released February 2026. Supports webpack 5 only (for webpack 4, use the 2.x branch). Peer dependencies require Stylelint >=13 up to 17, and Node.js >=18.12.0 (v5 breaking change). Key differentiators: integrates linting directly into webpack compilation, supports caching (enabled by default since v4.1.1), autofixing, and custom formatters. Ships TypeScript types. Alternative to running Stylelint as a separate process or using other linting plugins like eslint-webpack-plugin for styles.","status":"active","version":"5.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/webpack/stylelint-webpack-plugin","tags":["javascript","stylelint","lint","linter","plugin","webpack","typescript"],"install":[{"cmd":"npm install stylelint-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add stylelint-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add stylelint-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: webpack 5 required (plugin is a webpack plugin)","package":"webpack","optional":false},{"reason":"peer dependency: actual linter that performs the style checks","package":"stylelint","optional":false}],"imports":[{"note":"Package is ESM-first since v3.2.0; CommonJS require works in Node.js but may trigger ESM warnings. For webpack config, require is still commonly used.","wrong":"const StylelintPlugin = require('stylelint-webpack-plugin')","symbol":"StylelintPlugin","correct":"import StylelintPlugin from 'stylelint-webpack-plugin'"},{"note":"TypeScript type is exported for plugin options. Use import type for type-only usage.","wrong":"","symbol":"StylelintPlugin (type)","correct":"import type { StylelintPlugin } from 'stylelint-webpack-plugin'"},{"note":"Available since v5.0.0; defines the options object type.","wrong":"","symbol":"StylelintWebpackPluginOptions","correct":"import type { StylelintWebpackPluginOptions } from 'stylelint-webpack-plugin'"}],"quickstart":{"code":"// webpack.config.js\nimport StylelintPlugin from 'stylelint-webpack-plugin';\n\nexport default {\n  // ... other webpack config\n  plugins: [\n    new StylelintPlugin({\n      files: 'src/**/*.{css,scss,sass}',\n      fix: false,\n      cache: true,\n      cacheLocation: 'node_modules/.cache/stylelint-webpack-plugin',\n      context: __dirname,\n      extensions: ['css', 'scss', 'sass'],\n      exclude: ['node_modules'],\n      lintDirtyModulesOnly: false,\n      formatter: 'string',\n      configFile: '.stylelintrc.json',\n    }),\n  ],\n};","lang":"typescript","description":"Basic webpack config integrating StylelintPlugin with common options: files glob, caching enabled, and custom config file."},"warnings":[{"fix":"Upgrade Node.js to version 18 or later.","message":"Node.js 18 minimum required since v5.0.0","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"For webpack 4, use 'npm install stylelint-webpack-plugin@2'.","message":"Webpack 5 only since v3.0.0; webpack 4 users must use v2.x branch","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use 'import StylelintPlugin from 'stylelint-webpack-plugin'' instead of require().","message":"CommonJS require() style is deprecated in favor of ESM import","severity":"deprecated","affected_versions":">=3.2.0"},{"fix":"Add 'cache: false' to plugin options or delete cache directory manually when changing Stylelint config.","message":"Caching is enabled by default since v4.1.1; may cause stale results if cache not cleared","severity":"gotcha","affected_versions":">=4.1.1"},{"fix":"Upgrade to v5.1.0 if using Stylelint v16 or v17.","message":"Support for Stylelint 13 and 14 dropped in v5.1.0-? (check notes; v5.1.0 supports v13-v17)","severity":"deprecated","affected_versions":">=5.0.0 <5.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install stylelint --save-dev' in your project.","cause":"stylelint is not installed as a dependency.","error":"Error: Cannot find module 'stylelint'"},{"fix":"Run 'npm install stylelint-webpack-plugin --save-dev'.","cause":"Package not installed or not in node_modules.","error":"Error: Cannot find module 'stylelint-webpack-plugin'"},{"fix":"Use 'import StylelintPlugin from 'stylelint-webpack-plugin'' or for CommonJS: 'const StylelintPlugin = require('stylelint-webpack-plugin').default'.","cause":"Using import incorrectly (e.g., using named import instead of default).","error":"TypeError: StylelintPlugin is not a constructor"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}