tslint-loader
raw JSON → 3.5.4 verified Sat Apr 25 auth: no javascript maintenance
Webpack loader for TSLint, version 3.5.4, last updated in 2019. Integrates TSLint into webpack build pipeline to lint TypeScript files during compilation. Supports custom config files, type-checked rules, formatters, and file output. Compatible with webpack 1-4, but requires TSLint >=4.0.0. Key differentiator: seamlessly adds linting as a pre-loader step in webpack, with options to emit errors or fail builds on hints. Less active now due to TSLint deprecation in favor of ESLint with TypeScript.
Common errors
error Module build failed: TypeError: loader.runAsChild is not a function ↓
cause Incompatibility with webpack 4+ due to deprecated API.
fix
Use webpack 3 or lower, or switch to eslint-loader.
error Error: Could not load tslint-loader: The loader name is not recognized. ↓
cause tslint-loader not installed or not in node_modules.
fix
Run 'npm install --save-dev tslint tslint-loader'.
error TypeError: configFile is not a string ↓
cause configFile option expects a string path, but received another type.
fix
Set configFile to a string like 'tslint.json' or false.
error Error: Cannot find module 'tslint' ↓
cause Missing peer dependency tslint.
fix
Run 'npm install --save-dev tslint'.
Warnings
deprecated TSLint is deprecated in favor of ESLint with TypeScript. Consider migrating to eslint-loader or @typescript-eslint. ↓
fix Use eslint-loader with @typescript-eslint/parser and @typescript-eslint/eslint-plugin.
breaking Requires TSLint >=4.0.0, not compatible with TSLint 3.x. ↓
fix Update TSLint to version 4.0.0 or higher.
gotcha The loader must be applied as a pre-loader using 'enforce: pre' to ensure it runs before compilation. ↓
fix Set enforce: 'pre' in the rule configuration.
gotcha Webpack 1 uses 'preLoaders' and 'tslint' config property, while webpack 2+ uses 'rules'. ↓
fix Use appropriate configuration syntax for your webpack version.
gotcha Setting 'typeCheck: true' requires a valid tsconfig.json file and may slow down compilation. ↓
fix Ensure tsconfig.json exists and contains necessary compiler options.
Install
npm install tslint-loader yarn add tslint-loader pnpm add tslint-loader Imports
- tslint-loader wrong
import tslintLoader from 'tslint-loader'correct// In webpack config, use loader string 'tslint-loader'
Quickstart
// webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.ts$/,
enforce: 'pre',
use: [
{
loader: 'tslint-loader',
options: {
configFile: 'tslint.json',
emitErrors: true,
failOnHint: true,
typeCheck: true,
tsConfigFile: 'tsconfig.json'
}
}
]
}
]
}
}