Webpack excludes TypeScript from its bundling process

I'm encountering an issue with bundling my TypeScript projects. It appears that ts-loader is not recognizing TypeScript syntax.

The errors I'm seeing:

ERROR in ./src/common/components/chat/chatComponent.tsx
Module parse failed: The keyword 'interface' is reserved (10:0)
You may need an appropriate loader to handle this file type.
| import { ChatItemComponent, ChatMessageItem, isMessage, Props as Item } from "./chatItem";
|
| interface Props {
|   className?: string;
|   fullHistoryFetched?: boolean;

And

ERROR in ./src/common/closer.tsx
Module parse failed: Unexpected token (10:13)
You may need an appropriate loader to handle this file type.
| import * as chatItem from "./components/chat/chatItem";
| import * as chatItemStyles from "./components/chat/chatItem.css";
| import Timer = NodeJS.Timer;
| import { ImageComponent } from "./components/image/image";
| import { InitialsAvatar } from "./components/initialsAvatar";

My webpack.config.js looks like this:

const webpack = require('webpack');
const path = require('path');

module.exports = {
    mode: "development",
    devtool: "inline-source-map",
    entry: {
        index: './src/agent/index.tsx',
        preloader: './src/agent/preloader.js',
    },
    target: 'web',
    output: {
        path: path.resolve(__dirname, 'dist/agent'),
        filename: '[name].js',
        publicPath: '/dist/agent/'
    },
    module: {
        rules: [
            {
                test: /\.(ts|tsx)?$/,
                include: path.resolve(__dirname, 'src/agent'),
                use: [
                    {
                        loader: 'ts-loader'
                    }
                ]
            },
            ...
        ]
    },
    resolve: {
        extensions: ['.ts', '.tsx', '.js', '.jsx', '.json']
    }
};

Here is my tsconfig.json:

{
  "buildOnSave": false,
  "compileOnSave": false,
  "compilerOptions": {
    "alwaysStrict": true,
    "experimentalDecorators": true,
    "jsx": "react",
    "module": "commonjs",
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noUnusedLocals": true,
    "pretty": true,
    "removeComments": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strictNullChecks": true,
    "target": "es5",
    "lib": [
      "es2015",
      "dom"
    ],
    "types": [
      "jasmine",
      "node",
      "react"
    ]
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}

The versions I am using are:

"typescript": "2.5.3", "ts-loader": "4.0.1", "webpack": "^4.1.1.

Is there something I am overlooking? My tsconfig.json file specifies generating sources into ES5 so I believe babel is not required.

Answer №1

The issue lies with the include parameter in your configuration. By restricting the ts-loader to only look in the src/agent directory, you are encountering errors for files located in the src/common directory.
You can solve this problem by specifying an array as the value for the include parameter and listing all folders that contain TypeScript files.

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

Using React Material UI in Typescript to enhance the theme with custom properties

Struggling to customize the default interface of material ui Theme by adding a custom background property to palette. Fortunately, I found the solution thanks to this helpful shared by deewens. declare module '@material-ui/core/styles/createPalette& ...

Automated Import Feature in Visual Studio Code

I'm currently transitioning from Webstorm to Visual Studio Code due to the poor performance of Webstorm. However, I'm facing issues with Visual Studio Code not being very efficient at detecting and importing the dependencies I need. I find mysel ...

What is the most effective method for integrating Typedoc documentation into Confluence?

Looking to streamline my Typedoc documentation process by automating it for direct upload to the Confluence page. I've experimented with Sphinx, but Typedoc doesn't output the required RST file needed by Sphinx. ...

Class-validator: eliminate a field during validation depending on the value of another field

When using class-validator in conjunction with NestJS, I have successfully implemented the following: export class MatchDeclineReason { @IsString() @IsEnum(MatchDeclineReasonType) @ApiProperty() type: MatchDeclineReasonType; @ValidateIf(reason = ...

Display a list of items using *ngFor in a dropdown menu without using the optgroup

Is there a way to group data from *ngFor in the dropdown selection without using optGroup? You can find the JSON file link below: JSON Data Typescript Code getProducts() { if (this.products.length < 1) { this.productService.getProducts ...

Horizontal scroll functionality featured in a D3 bar graph

I'm currently working on implementing a bar graph with a selection dropdown that includes 3 values: By Date, By Week, By Month (where 'By Date' is the default option). When retrieving data from the backend for 'ByDate', I have a l ...

Finding a solution to the type issue of error handling in Route Handler with NextJS

I'm working on a route handler located at app/api/transactions/route.ts. Here's a snippet of the code: import { NextRequest, NextResponse } from "next/server"; import { AxiosError } from "axios"; import axios from "../axi ...

What sets apart two pieces of TypeScript code from each other?

When I first started learning TypeScript, I encountered an issue that has me stuck. In my code, there are two versions: in the first version, there is an object called name, and in the second version (which is essentially the same), the variable name has ...

Enhance the appearance of data in Angular using a pipe or alternative method

Currently in my Angular 8 application, I have some data displaying in a div like so: {"Information":"Information one","Output":[{"address1":"someaddress"},{"address2":"someaddress"},{"address3":"someaddress"},{"address4":"someaddress"}]} However, it&apos ...

A RxJS function that emits the final value from the first observable and then emits true from the second observable

Hello, I'm attempting to design a function that involves an observable (OBS) and a subject (SUB). The goal is to capture the last item from OBS while SUB is in state F, and then emit this particular value only when SUB transitions to state T. OBS ...

Trouble getting CSS to load in Webpack

I'm having some trouble setting up Webpack for the first time and I think I might be overlooking something. My goal is to use Webpack's ExtractTextPlugin to generate a CSS file in the "dist" folder, but it seems that Webpack isn't recognizi ...

Can ngFor be utilized within select elements in Angular?

I'm facing an interesting challenge where I need to display multiple select tags with multiple options each, resulting in a data structure that consists of an array of arrays of objects. <div class="form-group row" *ngIf="myData"> <selec ...

Tips for concealing the spinners on the numeric filter in Kendo Grid for Angular version 4/6

This particular column in my kendo grid is causing some issues <kendo-grid-column width="80" field="Savings" title="Savings" filter="numeric"> </kendo-grid-column> When I include this column, two icons for increasing and decreasing values a ...

Angular auto-suggest components in material design

Can someone assist me in resolving my issue? I am trying to incorporate an autocomplete feature with a filter into my form. .ts file : contactArray; selectedContact: IContact; myControl = new FormControl(); filteredContact: Observable<string[] ...

The inputs in the FormArray are not populated with the data from the JSON

I am struggling with outputting data from a JSON object to a FormArray. When I try to display the data, all I get is Object object. Can anyone suggest the best way to tackle this issue and offer advice on improving my code? Here is the StackBlitz link to ...

Tips for creating an array that aligns with the keys of a type in TypeScript

Currently, I am utilizing the Kysely SQL builder for JS based on Vercel's recommendation, despite the limited documentation and community support. This SQL builder is fully typed, allowing you to create a db object with a schema that recognizes table ...

How to Manage API Requests in React Native?

I am in the process of familiarizing myself with react native and attempting to communicate with an API helper that I have implemented within one of my screen files. While I suspect there may be a syntax error causing issues, I also wonder about the overal ...

Mongoose Wraps Every Item Inside a Collection

Hello everyone! I'm facing an issue with mongoose. It seems to be adding an array of arrays to the database instead of just an object array, and it's packaging each object into its own array. Can someone help me figure out what's going wrong ...

Integrate Materializecss with Angular2 project using Webpack

I'm relatively new to exploring the Angular2 framework and its various components, and I'm trying to understand how everything fits together. Please excuse me if some of my questions seem basic. Recently, I set up a fresh Angular2 application us ...

What is the best way to manage data that arrives late from a service?

Within my Angular application, I have a requirement to store data in an array that is initially empty. For example: someFunction() { let array = []; console.log("step 1"); this.service.getRest(url).subscribe(result => { result.data.forEach( ...