Updates to TypeScript 2.1.4 causing disruptions in the webpack ts-loader integration

After upgrading from Typescript 2.0.10 to 2.1.4, it seems that something in webpack, webpack-stream, ts-loader, or gulp is not working correctly. It no longer respects the entry point or gulp source glob specified; instead, it includes all .ts files in the project, even those in the /server source folder, rather than just the ts files in /client and app.ts as intended. Is there a better way to handle this with the newer version?

Here is the relevant code snippet from the gulp file:

const serverPath = 'server';
const clientPath = 'client';
const buildPath = 'build';
const paths = {
    server: {
        scripts: [
            `${serverPath}/**/*.ts`
        ]
    },
    client: {
        files: [
            `${clientPath}/**/*`
        ],
        scripts: [
            `${clientPath}/**/*.ts`
        ],
        entry: `${clientPath}/app.ts`
    }
};


gulp.task('build:client', cb => {
    gulp.src(paths.client.entry)
        .pipe(webpackStream(webpackConfig, webpack))
        .pipe(gulp.dest(`${buildPath}/${clientPath}`));
    cb();
});

Here is the relevant code snippet from the webpack configuration:

entry: {
    app: './client/app.ts'
}

ts: {
    configFileName: './tsconfig.json'
}

resolve: {
    extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js']
}

module: {
    loaders: [
        { test: /\.ts$/, loader: 'ng-annotate-loader!ts-loader' }
    ]
}

And here is the content of tsconfig.json:

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "removeComments": false,
        "noImplicitAny": true,
        "sourceMap": true,
        "inlineSources": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true
    }
}

Output with Typescript 2.0.10:

ts-loader: Using <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="097d70796c7a6a7b60797d493b2739273839">[email protected]</a> and /Users/chris/code/class-app/tsconfig.json
[20:47:36] Version: webpack 1.14.0
Asset       Size  Chunks             Chunk Names
app.js.map  950 bytes       0  [emitted]  app
app.js  550 bytes       0  [emitted]  app

Output with Typescript 2.1.4:

ts-loader: Using <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="85f1fcf5e0f6e6f7ecf5f1c5b7abb4abb1">[email protected]</a> and /Users/chris/code/class-app/tsconfig.json
server/api/thing/thing.controller.ts(17,16): error TS2322: <ts error in server portion, not relevant>
[20:53:03] TypeScript: 1 semantic error
[20:53:03] TypeScript: emit succeeded (with errors)
Unhandled rejection Error in plugin 'webpack-stream'
Message:
/Users/chris/code/class-app/server/api/thing/thing.controller.ts <same as above>

Answer №1

It turns out the issue with TypeScript in WebPack has been affecting the server code without my knowledge, even though it wasn't supposed to be. While I originally intended to address the server TS problem caused by the TypeScript update, it actually revealed that WebPack has been compiling files incorrectly all this time. To confirm, I purposely created an issue in the server ts using the old version of TypeScript and encountered the same error.

I still need to investigate why all my TS files are being compiled, instead of just those in the /client directory. I will create a separate question to seek help on this matter.

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

Aligning two identical components within the same container when triggered by a single click

Currently, I am exploring Angular 2 and Typescript and have been developing a pager component for a table. The pager functions correctly, but I have encountered an issue with having two pagers - one above the table and one below it. When the next button on ...

What is the process of extracting an observable from another observable using the pipe method?

Is there a more efficient way to convert an Observable of Observables into an array of Observables in my pipe method? Here is the scenario: // The type of "observables" is Observable<Observable<MyType>[]> const observables = this.http.get<M ...

Converting an array with objects to comma separated strings in javascript using (ionic , Angular , NodeJS , MongoDB)

Retrieving specific data from an API array: let passions = [ {_id: "60a1557f0b4f226732c4597c",name: "Netflix"}, {_id: "60a1557f0b4f226732c4597b",name: "Movies"} ] The desired output should be: ['60a1557f0b4f226 ...

What might be causing my observable to fail to return a value?

I'm currently utilizing an API known as ngx-pwa localstorage, which serves as a wrapper for an indexeddb database. Within my Angular project, I have a service that interacts with this database through a method called getItem: getItem(key: string) { ...

Collaborative service utilization in Angular 2

My goal is to create a shared service for my app. import { Injectable } from '@angular/core'; @Injectable() export class SharedService { testService() { console.log('share!'); } } However, when I attempt to inject this shared ...

Selecting a filter for an array of objects

I'm struggling to implement a search feature in my mat-select DropDown. The existing options I've found online aren't quite working for me due to the object array I am passing to the Dropdown. Any assistance or guidance on this matter would ...

Enhancing Subscription Collection with Angular and RX Framework

Exciting Update! After successfully finding the solution, I created a handy ng2-rx-collector tool inspired by the accepted answer to simplify the process even further. It's designed to assist anyone who might encounter similar challenges in the futur ...

Creating spec.ts files for components by hand: A guide

Currently, I am facing an issue where the automatic generation of spec.ts files has been disabled by the developers when they created the components. To address this, I manually created the spec.ts files by copying over an existing one into each component, ...

Async/await is restricted when utilizing serverActions within the Client component in next.js

Attempting to implement an infinite scroll feature in next.js, I am working on invoking my serverAction to load more data by using async/await to handle the API call and retrieve the response. Encountering an issue: "async/await is not yet supported ...

Error encountered in Typescript parsing when setting EXTEND_ESLINT to true in create-react-app

Demo on GitHub - Simplified Version We are currently in the process of migrating our create-react-app project from Flow to Typescript incrementally. As part of this migration, I had to disable some ESLint rules that were causing issues. To customize ESLin ...

Creating a customized Axios instance in Typescript can provide more flexibility and control over

I am looking to create an API with a customizable instance using Axios. Ideally, I want to be able to use a basic instance like this: api.get("url")... In addition, I would like to have the flexibility to add dynamic bodies and access them using something ...

When importing a module, the function in the ts file may not be recognized or located

While attempting to create a VSTS (Azure Devops) Extension, I encountered a perplexing issue. Within my HTML page, I have a button element with an onclick listener: <!DOCTYPE html> <head> <script type="text/javascript"> VS ...

What is the name of the file that contains a class?

I am curious about identifying the file that called a specific class: database.ts class Database { constructor() { console.log(`I want to know who called this class`); } } server.ts import Database from 'database.ts'; new Databa ...

Creating and sharing a project in Typescript

My typescript project tends to have its code scattered across multiple files during development. Is there a recommended method for packaging this project into a single js and d.ts file for distribution? ...

Is it necessary to utilize RequestHandler every time I create an Endpoint in Sveltekit?

As I work on creating a Todo website, I came across a video tutorial about building a Svelte fullstack app. The teacher in the video demonstrated the use of RequestHandler to create an endpoint. However, in the SvelteKit documentation, it recommends using ...

Utilizing Partial Types in TypeScript Getter and Setter Functions

Within the Angular framework, I have implemented a component input that allows for setting options, specifically of type IOptions. The setter function does not require complete options as it will be merged with default options. Therefore, it is typed as Pa ...

What is the best approach to ensure that the variables within a function of an imported component in Angular 8 reflect their current values instead of their initial values?

Within the constructor of a component, I am declaring a private variable for an imported component. For example: constructor(private x: Xcomponent){} Afterwards, I am calling a function, scanx(), that is declared inside Xcomponent. x.scanx() Within the ...

Discover the length of a video clip

Before I upload a video file, I need to determine the duration of the video. How can I gather this information? I am currently utilizing Angular 11.0.9 async upload(event: any){ this.currentFile = event.target.files[0]; // Upload Logic } ...

What steps should I take to retrieve my information from a typescript callback function?

While I am familiar with using callbacks in JavaScript, I have recently started learning Angular and TypeScript. I am facing an issue with getting my data from a service back to where I need it after executing the callback function. The callback itself i ...

Managing the Jetbrains internal server using code

While WebStorm offers an amazing LiveEdit function that is said to be superior to LiveReload, it unfortunately does not automatically detect changes in all file types being utilized. Specifically, it tends to overlook modifications in Stylus and Jade files ...