The failOnError option of eslint-loader is ineffective when used in conjunction with ts-loader and webpack-dev-server

Introduction

Issues Encountered

  • The eslint-loader does not halt compilation and displays a ts-loader error.
  • Even after rewriting the TypeScript code, the ts-loader error persists as an old one.

Step-by-Step Procedure

1. Launch dev-server: Run yarn start =
webpack-dev-server --mode development

package.json

{
  "name": "eslint-ts-loader-error",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "start": "webpack-dev-server --mode development",
    "build": "webpack --mode production"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "2.30.0",
    "@typescript-eslint/parser": "2.30.0",
    "babel-loader": "8.0.6",
    "eslint": "6.8.0",
    "eslint-loader": "4.0.2",
    "ts-loader": "6.2.2",
    "typescript": "3.8.3",
    "webpack": "4.33.0",
    "webpack-cli": "3.3.4",
    "webpack-dev-server": "3.7.1"
  }
}

webpack.config.js

const path = require('path');

module.exports = {
  entry: './src/main.ts',
  output: {
    path: path.resolve(__dirname, 'dist/'),
    filename: '[name].js',
  },
  module: {
    rules: [
      {
        test: /\.(ts|tsx)$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'ts-loader',
          },
        ],
      },
      {
        test: /\.(ts|tsx)$/,
        enforce: 'pre',
        exclude: /node_modules/,
        use: [
          {
            loader: 'eslint-loader',
            options: {
              failOnError: true,
            },
          },
        ],
      },
    ],
  },
};

2. Modify and save .ts file.

main.ts

const a: string = 100;
console.log(a);

-> Error: ts-loader (Expected behavior)

ts-loader: Type '100' is not assignable to type 'string'.

3. Modify and save .ts file.

const a: string = 100;
// console.log(a);

-> Error: eslint-loader, ts-loader (Unexpected)

eslint-loader: 'a' is assigned a value but never used  no-unused-vars
ts-loader: Type '100' is not assignable to type 'string'.

[Expected]: When there's an error in eslint-loader, the compilation should stop without displaying ts-loader errors.

4. Modify and save .ts file.

const a: boolean = 100;
// console.log(a);

-> Error: eslint-loader, ts-loader (Unexpected)

eslint-loader: 'a' is assigned a value but never used  no-unused-vars
ts-loader: Type '100' is not assignable to type 'string'.

The ts-loader error remains outdated, indicating a potential issue with the processing pipeline.

Is this a matter attributable to webpack-dev-server or perhaps eslint-loader?

Any insights or assistance would be greatly appreciated.

System Details

  • Operating System: macOS Catalina v10.15.4
  • Node.js Version: v12.16.2
  • npm Version: v6.14.4
  • yarn Version: v1.22.4

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to retrieve an object based on a custom key type in TypeScript when using a

I have a custom class called Foo: class Foo { constructor(public v: any) { } } And I have a map where Foo is my Key: const map = new Map<Foo, string>(); As far as I know, TypeScript does not support comparison overloading. How can I ensure ...

AWS Amplify is failing to maintain the user session post a successful login

Currently, I am developing an aws-serverless application using React. My main issue lies in the authentication process with aws-amplify. The authentication works smoothly, but the session is not being preserved. During the signing-in stage: await Auth.s ...

The cube from Three.js refuses to render after being bundled with Webpack in a Wordpress environment

I am facing an issue while trying to incorporate three.js with WordPress using webpack. The problem lies in the fact that the 3D cube is not showing up inside the canvas. <div class="div" id="canvas"></div> appears to be em ...

Navigating between components in angular2 modules: A tutorial

Currently, I am utilizing angular2 Final version for my development tasks. Within my project, I have established 3 distinct modules: AppModule ProjectModule DesignerModule In the past, I solely had AppModule which integrated the following RoutingModule ...

Unable to find the locally stored directory in the device's file system using Nativescript file-system

While working on creating an audio file, everything seems to be running smoothly as the recording indicator shows no errors. However, once the app generates the directory, I am unable to locate it in the local storage. The code I am using is: var audioFo ...

Experiencing extended loading periods in Ionic 2 app

Struggling with slow load times on my Ionic 2 application. Even though I am using minimal plugins, the start up time is taking minutes and a white screen appears after the splash screen disappears. ...

Troubleshooting Angular4 and TypeScript Compile Error TS2453: A Comprehensive

I'm facing an issue in my Angular4 project build process which I find quite perplexing. The error seems to be related to the import of certain components such as Response, Headers, and Http from @angular. Whenever I attempt to build my project, it thr ...

Utilizing React Router with the power of useCallback

My route configuration is set up as follows: const defineRoutes = (): React.ReactElement => ( <Switch> <Redirect exact from="/" to="/estimates" /> <Route exact path="/estimates" component={CostingPa ...

How to Fix TypeScript React JS Lint Error: Missing Dependency in React Hook useEffect without Disabling Lint or Adding Additional Dependencies

As I build a Web application using React JS and TypeScript with React hooks, I encountered a warning when utilizing a custom hook in my Component. The warning states that the dependency 'productsHook' is missing in the useEffect hook. One way to ...

Creating an Http interceptor in Ionic 3 and Angular 4 to display a loading indicator for every API request

One of my current challenges involves creating a custom HTTP interceptor to manage loading and other additional functions efficiently. Manually handling loading for each request has led to a considerable increase in code. The issue at hand: The loader is ...

Creating an interface for React props

Hey everyone, I'm facing an issue and need some advice. I prefer using interfaces to maintain readability and utilize intellisense in my code. However, I'm struggling with implementing this approach when working with data passed through props. H ...

Making if-else statements easier

Greetings! I have a JSON data that looks like this: { "details": { "data1": { "monthToDate":1000, "firstLastMonth":"December", "firstLa ...

Tips on downloading an image using the URL in nestjs

I'm trying to retrieve a link and save the associated image in the static folder, but I seem to be encountering some issues with my code. Here's what I have so far: @Injectable() export class FilesService { createFileFromUrl(url: string) { t ...

Cross-origin resource sharing (CORS) seems to be creating a barrier for the communication between my Angular

During the process of developing an Angular and NestJS app with NGXS for state management, I encountered a CORS error while serving my application. The error message in the console indicated: Access to XMLHttpRequest at 'localhost:333/api/product-i ...

The parameter type 'string | null' cannot be assigned to the value function 'ValueFn<SVGPathElement, Datum[], string | number | boolean | null>'

I recently delved into the world of d3 and attempted to create a simple line chart using d3, TypeScript, and react. However, I keep encountering a TypeScript error whenever I try to implement it. Strangely, I can briefly see my chart before it disappears a ...

Dealing with the error "TypeError: Unable to access the property 'useState' of null" in React Framework - Developing an NPM Package

My goal is to develop a local npm package that includes various React components under the name myscript-package. ./package.json { "name": "pack-script", "version": "0.1.0", "private": true, "d ...

How do I specify the return type of a function in Typescript that can return more than one type?

I am facing a situation where I have a method called getFilters that retrieves various types of values. getFilters(): IListFilteringType {...} type IListFilteringTypeMultiSelect = (string | number)[]; type IListFilteringType = boolean | string | number | ...

Ensure the variable is valid by using a type guard in the false branch

I am attempting to use a type guard to narrow down a complex type. In my scenario, I want the false branch of the type guard to recognize the complement of the narrowed type. interface Model { side: 'left' | 'right'; } interface LeftMo ...

Retrieve the JSON information specifically for the selected ID

Having a set of JSON data, with 2 base IDs and attachment data within each ID. The goal is to click on a base ID and display its attachment data on a separate page. How can I retrieve information for the clicked ID only? { "_embedded": { "deli ...

The application is having trouble accessing the property 'isXXXXX' because it is undefined

My attempt to utilize a shared service in one of my components has been successful when used with the app's root component. However, I encountered an error when trying to implement it on another module or dashboard. https://i.sstatic.net/x3rRv.png s ...