Issues encountered when attempting to use Angular2 with SystemJs and typescript transpiler

I've encountered an issue with my TypeScript transpiler setup. My @angular component isn't loading, and I'm getting this error message: ZoneAwareError:

"Error: core_1.Component is not a function
  Evaluating http://127.0.0.1:64223/app/app.component.ts
  Evaluating http://127.0.0.1:64223/app/app.module.ts
  Evaluating http://127.0.0.1:64223/app/main.ts
  Loading app
    at LoaderError__Check_error_message_for_loader_stack (http://127.0.0.1:64223/node_modules/systemjs/dist/system.src.js:78:11) [<root>]
    ... more stack trace ...

While I understand that using a transpiler in production isn't recommended, I'm utilizing it in my development environment. Here's my current configuration:

tsconfig.json

{
  "disableCompileOnSave": true,
  "compileOnSave": false,
  "compilerOptions" : {
    "target" : "ES5",
    "module" : "commonjs",
    "experimentalDecorators" : true,
    "noImplicitAny" : true
  }
}

Lastly, here are the relevant components and modules:

app/app.component.ts

import { Component } from '@angular/core';
console.log('@angular/core');
@Component({
    selector: 'app',
    template: `
    <h1>{{title}}</h1>
    <h2>My favorite hero is: {{myHero}}</h2>
    `
})
export class AppComponent {
    title = 'Tour of Heroes';
    myHero = 'Windstorm';
}

app/app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';

@NgModule({
    imports: [BrowserModule],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})

export class AppModule { }

and app/main.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app.module';

platformBrowserDynamic().bootstrapModule(AppModule);

I suspect there's an issue with the system.js configuration. I've been struggling with this problem for hours now and would appreciate any assistance.

Answer №1

I encountered a similar issue today and managed to find a solution that worked for me. My tsconfig setup looked like this:

"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "system",
"moduleResolution": "node",
"noImplicitAny": false,
"noEmitOnError": false,
"removeComments": false,
"sourceMap": true,
"target": "es5"

}, "exclude": [ "node_modules", "wwwroot" ] }

Upon comparing it with the sample provided in the Angular Quickstart, I noticed that they were using commonjs.

"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": false,
"noEmitOnError": false,
"removeComments": false,
"sourceMap": true,
"target": "es5"

}, "exclude": [ "node_modules", "wwwroot" ] }

After recompiling the ts files with the updated configuration, the error was resolved.

Answer №2

Have you tried out the latest Angular 2 project generator recommended by the developers? The angular-cli now incorporates Webpack (https://github.com/angular/angular-cli).

In addition to Webpack features, the angular-cli offers component generators, services, and more for your convenience.

Answer №3

I encountered a similar issue and found a solution by downgrading my systemjs version from 0.20.12 to 0.19.40. Surprisingly, this resolved the problem and my app started working again. I got this suggestion from a source mentioned here. It's worth noting that my tsconfig includes "module": "system". Also, don't forget to remove the caret symbol from the systemjs version string.

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

Troubleshooting TypeScript compatibility with SystemJS when encountering problems with the .js extension

Initializing my TypeScript file with the import statement below. It's important to note that the lack of a .ts extension indicates that I am importing a TypeScript module: import githubService from './github.service'; Through transpilation ...

Ways to turn off logging for an Angular application using MSAL

I have integrated the Microsoft Authentication Library msal into my Angular application. However, when I deploy the production version of the app, I notice these logs appearing in the console. What is the best way to turn off this logging? https://i.sstat ...

When running tests on Angular components that interact with Firebase, errors occur, specifically in the creation phase, resulting in a NullInjectionError. However

Currently, I am in the final stages of developing a chat application using Angular and Firebase. Everything appears to be working smoothly until I encountered numerous strange errors during testing. One particular issue is the inability to create certain ...

Regulation specifying a cap of 100.00 on decimal numbers entered into a text input field (Regex)

I have created a directive that restricts text input to only decimal numbers in the text field. Below is the code for the directive: import { HostListener, Directive, ElementRef } from '@angular/core'; @Directive({ exportAs: 'decimal ...

How can we eliminate the modal-open class in Angular when transitioning to a different URL?

Currently, I am facing an issue with a bootstrap modal. There is a button inside the modal which upon clicking should navigate the current component to another component named 'questions'. The problem arises when the new component is loaded, as t ...

What could be causing this particular issue when using the Firestore get() method? The error message states: "ERROR TypeError: snaps

In my current Angular project, I am utilizing Firebase Firestore database and have implemented the following method to execute a query: findArtistBidsAppliedByCurrentWall(bid):Observable<Bid[]> { console.log("findArtistBidsAppliedByCurrent ...

Troubleshooting Typescript compilation issues following an upgrade to a React Native project

I am facing a challenge while updating a react native project from version 0.63.3 to 0.67.0. When attempting to run npm run tsc, I encounter numerous errors indicating that the typescript packages are not compatible with their original packages. Here is a ...

Implementing validation for a dynamic form

I'm currently working on a basic form that includes multiple questions with dropdown options as answers. Here's what I've managed to accomplish so far. I've successfully implemented a dynamic form where the data loads correctly into t ...

Using TypeScript to access global variables from inside a method

Hi everyone, I'm trying to figure out how to access variables from the global scope (this) within 2 methods. Any help would be greatly appreciated. location: any; doSomethingOne() { Geolocation.getCurrentPosition().then((resp) => { ...

Replicating entities in TypeScript

I am currently developing an Angular 2 application using TypeScript. In a User Management component, I have implemented a table that displays all the users in my system. When a user is clicked on within the table, a form appears with their complete set of ...

Using MUI DatePicker and react-hook-form to implement a date picker in the format DD/MM/YYYY

I have developed a custom datePicker component that combines react-hook-form and Material UI. However, I am encountering an issue where the values are being displayed in the format: "2024-04-10T22:00:00.000Z" Below is the code snippet: import { Localizati ...

A guide to extracting attribute values from HTML using Angular 4

I am currently working on an Angular 4 project where I needed to implement drag and drop functionality. To achieve this, I utilized the ng2-dragula plugin. Now, I have a new requirement which involves extracting the data-id attribute from each row after it ...

Is there a method or alternative solution for deconstructing TypeScript types/interfaces?

Imagine a scenario where a class has multiple type parameters: class BaseClass<T extends T1, U extends U1, V extends V1, /* etc. */ > Is there a method to consolidate these type arguments in a way that allows for "spreading" or "destructuring," sim ...

Retrieve the array from within the string

Any suggestions on how I can extract the array from this string? The current string is: "['Biller.Customer.Data@Taxonomy', 'Product.Platform and Enterprise Services Data.Data@Taxonomy']" I need to extract it to look like thi ...

What is the best way to list the choices associated with a specific category?

The Node.js package I'm currently working with requires an argument of a specific type, which I can see is defined through a TypeScript declaration as follows: export declare type ArgType = 'A' | 'B' | 'C'; I am interes ...

The compilation of angular-cli version 25.5 encountered an error during module build

Issue Upon upgrading angular-cli from 22.1 to 25.5 (installing angular-cli@latest) and angular from version 2.2.3 to 2.3.1, the following problem occurred: ERROR in ./src/app/app.module.ts Module build failed: TypeError: Cannot read property 'text&a ...

Eliminate duplicate dropdown options in Angular 2 using a filter function

Is there a way to filter reporting results in an Angular 2 dropdown list? I am currently attempting to do so within the *ngFor template but haven't had any success. I will also try using a custom pipe. The data is coming from a JSON array. Specificall ...

Jest is unable to handle ESM local imports during resolution

I am encountering an issue with my Typescript project that contains two files, a.ts and b.ts. In a.ts, I have imported b.ts using the following syntax: import * from "./b.js" While this setup works smoothly with Typescript, Jest (using ts-jest) ...

GitHub Actions causing build failure in Angular project exclusively

I've encountered an issue where the GitHub Action workflow fails to compile an Angular project, even though it works fine on my local machine and that of my colleagues. It's worth noting that I'm using npm ci instead of npm install. The err ...

What is the best way to update the key value with an onclick event when the key value is already in the array using TypeScript?

In this scenario, I have set up an onclick function in order to retrieve the Product_id, Product_name, and Price from the detailss array. These values are then being stored in a local storage array called wishlist. However, I am currently facing a challen ...