Using ts-loader with Webpack 2 will result in compatibility issues

Lately, I've been working on setting up a basic Angular 2 (TypeScript) application with Webpack 2 for bundling.

However, I'm encountering numerous errors when using ts-loader to process TypeScript (.ts) files. It seems like ts-loader is not excluding the node_modules directory despite specifying it in the webpack configuration.

I need assistance in configuring my webpack setup so that TypeScript can be transpiled correctly and bundled seamlessly with Webpack. Any help would be greatly appreciated.

Webpack.config.js

var webpack = require('webpack');

module.exports = {
    entry: './src/main.ts',
    output: {
        filename: './dist/bundle.js',
    },
    resolve: {
        extensions: ['.ts', '.tsx', '.js']
    },
    module: {
        loaders: [{
            test: /\.tsx?$/,
            exclude: /node_modules/,
            loader: 'ts-loader'
        }]
    },
    plugins: [
        new webpack.ContextReplacementPlugin(
            /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
            __dirname
        ),
    ]
};

package.json

{
    "name": "tiptip-webpack",
    "version": "1.0.0",
    "description": "",
    "main": "webpack.config.js",
    "scripts": {
        "dev": "webpack -d --watch"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
        "@angular/common": "2.4.6",
        "@angular/compiler": "2.4.6",
        "@angular/core": "2.4.6",
        "@angular/forms": "2.4.6",
        "@angular/http": "2.4.6",
        "@angular/platform-browser": "2.4.6",
        "@angular/platform-browser-dynamic": "2.4.6",
        "@angular/platform-server": "2.4.6",
        "@angular/router": "3.4.6",
        "@angularclass/conventions-loader": "^1.0.2",
        "@angularclass/hmr": "~1.2.2",
        "@angularclass/hmr-loader": "~3.0.2",
        "core-js": "^2.4.1",
        "http-server": "^0.9.0",
        "ie-shim": "^0.1.0",
        "jasmine-core": "^2.5.2",
        "reflect-metadata": "^0.1.9",
        "rxjs": "5.0.2",
        "zone.js": "0.7.6"
    },
    "devDependencies": {
        "source-map-loader": "^0.2.0",
        "ts-loader": "^2.0.3",
        "typescript": "^2.2.0",
        "typings": "^2.1.0",
        "webpack": "^2.2.0"
    }
}

Error messages after running 'npm run build' https://i.stack.imgur.com/BFblk.png

Answer №1

The issue at hand is related to TypeScript rather than webpack. While webpack ignores the node_modules directory, TypeScript raises concerns due to its lack of knowledge about types such as Map or Set, which are ES6 features. By setting the target in the compilerOptions to es5, these types are excluded from compilation and their definitions become unknown to TypeScript. According to the documentation on compiler options:

Note: If --lib is not specified, a default library is injected. The default injected library includes:
► For --target ES5: DOM, ES5, ScriptHost
► For --target ES6: DOM, ES6, DOM.Iterable, ScriptHost

To address this issue, you can specify the lib option with es6 (or any higher version like es2017):

"lib": ["es6", "dom"]

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

Is there a way to implement retry functionality with a delay in RxJs without resorting to the outdated retryWhen method?

I'd like to implement a retry mechanism for an observable chain with a delay of 2 seconds. While researching, I found some solutions using retryWhen. However, it appears that retryWhen is deprecated and I prefer not to use it. The retry with delay s ...

Retrieve a particular element from an array within a JSON object using Ionic

I am currently facing a challenge in extracting a specific array element from a JSON response that I have retrieved. While I can successfully fetch the entire feed, I am struggling to narrow it down to just one particular element. Here is what my service ...

The webpack development server operates on a separate port

Currently, my IIS server is serving up my WebApi and AngularJS project on port 80 with the alias mywebsite.local-dev.com in the hosts file. I have configured webpack to bundle everything and now I want to add webpack dev server so that changes to a file t ...

Webpack compilation encountering an issue

I encountered an error while attempting to run my angular2 project. This issue arose after transitioning from a PC with Ubuntu to MacOS X. The Node version is 7.7.4, and the npm version is 4.1.2. I am executing npm webpack-dev-server --inline --progress ...

Troubleshooting problems with Angular CLI installation on a Mac machine

Having trouble installing an older version of Angular CLI as it keeps defaulting to 6.0.3. https://i.stack.imgur.com/JZFz4.png Any thoughts on why the @angular-devkit/core error version is showing up? Any suggestions? Current npm version: 6.0.1, Node.js ...

Exploring the world of form interactions in Angular: A guide to creating dynamic element communication

I have created a form using Angular, and I want to display a specific value in my input field when an element is selected from the dropdown. Additionally, since the values in the dropdown are fetched from a server, I want to show a corresponding label for ...

Please explain the significance of the question mark in the statement `impliedTokenType: ?string`

Stripe elements have a question mark before the type in this GitHub repository: link The syntax I expected was impliedTokenType?: string, but it actually is impliedTokenType: ?string. Can someone explain the difference between the two? ...

Using alternate variables in the watchQuery() function in Apollo Angular will generate the cached data

Currently, I am implementing a feature in my project that allows users to access and analyze data based on various parameters such as year, location, and gender. Below is the code snippet that I have developed for this feature: this._querySubscription = ...

Developing Angular applications with numerous projects and libraries in the build process

The other day I successfully deployed the initial version of our front-end application, but encountered some confusion during the build process setup. Many Angular apps do not utilize the workspace feature unless they are creating multiple standalone appli ...

An issue occurred in resolving dependencies for the UsersService in Nest

I've been experimenting with Nest a bit, attempting to create a module that I can publish on my private repository for reuse in future projects. However, I've run into an error: ERROR [ExceptionHandler] Nest can't resolve dependencies of the ...

Does it follow standard practice for Array.filter to have the capability to also perform mapping on an array of objects?

While experimenting with Array.filter, I made an interesting discovery. By forgetting to include an equality check, my array was unexpectedly mapped instead of filtered. Here is the code snippet that led to this result: const x = [{ name: 'user' ...

What causes the useEffect hook to render twice in a Next.js application?

Within my Next.js application, I am seeking a way to verify whether a user has permission to access a particular page. While using a context, I encountered an issue where my useEffect hook was returning both the updated and default values. How can I ensure ...

Warning issued by Angular 7 indicating the usage of the routerLink directive and advising against navigation triggered outside the Angular zone

Encountering difficulties while working with the Angular framework to ensure smooth functioning of my application, I am currently facing an obstacle with routing. The structure includes a main AppComponent and a app-routing.module.ts file for navigation ma ...

Upgrade from AngularJS to the latest version of Angular, version 8

I'm trying to convert this AngularJS code into Angular 2+, but I'm having some trouble. Any ideas on how to do it? I've searched around, but this specific line is confusing me. scope.variable.value = event.color.toHex() Old Code: functi ...

Encountering complications in Edge browser due to triggering click on form submit button in Angular 2/4 forms

I have encountered a situation where I must trigger my form submission through code because the submit button is hidden from view. I utilize a method to simulate a button click (as there is a common button for all forms) using the following approach. cons ...

Provider not found: ConnectionBackend – NullInjectorError

I encountered the following error while attempting to load the webpage. Despite trying various suggestions from other sources, I have been unable to find a solution. Below the error stack lies my code. core.js:7187 ERROR Error: Uncaught (in promise): Null ...

Tips on applying a class to a host element using @hostbinding in Angular 2

I've been wanting to assign a class to the host element of my component, and initially I used the host property in this manner: @Component({ selector: 'left-bar', host: { 'class': 'left-bar' }, templateUrl: 'a ...

Exhibiting object.name values within a sheetJS Excel spreadsheet

I'm in the process of generating a sheetJS xlsx sheet within my Angular application using an array of models. Each model is structured as follows: { id: number, category: { id: number, name: string, }, name: string } My goal is to display t ...

What could be causing issues with my Angular and Express.js Server-Sent Events implementation?

Objective: Implement Server-Sent Events in Angular App with Express Backend Issue: Client does not receive Server-Sent Events Backend Implementation router.get('/options/:a/:b/:c', async (req, res) => { console.log('options endpoint c ...

Creating a specialized Docker image for Angular 9 production deployment

I don't have much experience with frontend development, but I'm currently working on creating a Docker image for an Angular 9 application. Here's what I've tried: ARG NODE_VERSION=12.16.1 # stage - # 1 FROM node:${NODE_VERSION}-buster- ...