SystemJS loader does not support the inclusion of .js files when importing Angular internal script files

I am currently facing an issue in my angular2 application where I am attempting to load TypeScript compiled JavaScript from a different server. The problem arises when I try to load the JavaScript file without the .js extension, resulting in a REST call without the .js extension and subsequently receiving a 404 error.

error
VM9887:1274 GET http://localhost:9099/OfferFinder7oct/app/app.module 404 (Not Found)

In more detail, the error occurs because SystemJS is attempting to load http://localhost:3000/app/app.module as "./app.module" but fails to reach http://localhost:3000/app/main.js


System.import('app').catch(function(err){ console.error(err); });

//system.config.js
/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      app: 'app',
      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
      '@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',

      // other libraries
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      },
      'angular-in-memory-web-api': {
        main: './index.js',
        defaultExtension: 'js'
      }
    }
  });
})(this);

Answer №1

To enable default file extension support, simply add defaultExtension: 'js' to the main section of your configuration settings. This will ensure that your configuration properly recognizes files without any extensions.

Your updated configuration should resemble the following:

(function (global) {
  System.config({
    defaultExtension: 'js',
    paths: {
      // Create aliases for paths
      'npm:': 'node_modules/'
    },
    // Specify where the System loader should search for resources
    map: {

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

"Positioning a Snackbar Message in the Center of the Screen in Angular: A Step-by-Step

I have a snackbar that I am displaying on button click. Here is the button: .html <button mat-icon-button (click)="UpdateCandidateData(row)" matTooltip="Save Changes" matTooltipPosition="left" color=" ...

How can I incorporate multiple quality sources into a flowplayer using Angular?

Is there a way to add multiple sources with different qualities like 1080p, 720p etc.? Thank you in advance. flowplayer('#my_player', { src: '../assets/videos/video_1080p.mp4', // title: 'This is just demo&apo ...

What is the best way to notify the parent Observable of an inner Observable’s error or success within nested Observables?

How can the outer Observable be notified of success or error in nested Observables? Why are onNext and onCompleted undefined within the inner Observable? public updateDocument(item: Document): Observable<any> { this.firstUseOfflineContainer(); ...

Pass the value of the search input to child components in Angular 2

Within my Angular 2 application, I am faced with the task of sending the value from an HTML search input to 3 child components only when the user pauses typing for 300ms and has entered a different value than what was previously in the input field. After r ...

Displaying Angular validations upon page load

We're currently tackling the Angular 4 form and have implemented some validation on the input field. The issue we're facing is that the validation shows up as soon as the page loads, but we actually want it to trigger when the form is submitted o ...

The implementation of combineSlices in reduxjs/[email protected] is an essential feature for managing

I am struggling to figure out how to properly useAppSelector with LazyLoadedSlices: Here is the setup of my store // @shared/redux/store.ts // comment: https://redux-toolkit.js.org/api/combineSlices // eslint-disable-next-line @typescript-eslint/no-empty ...

Angular CDKScrollable not triggering events

I'm having trouble making the angular CdkScrollable work when creating my own div: <div class="main-section" id="mainsection" #mainsection CdkScrollable> <div class="content" style="height: 300px; backgr ...

Angular application in a subdirectory experiencing a looped redirection issue

I am currently in the process of setting up an Angular application to be hosted from a subdirectory of an existing website. The main website is located at https://localhost/abc, while the Angular app is being served at http://localhost:4200 using ng serve. ...

Unable to remove a OneToMany entry in TypeORM

I am currently working with the following database schemas: @Entity() export class Question extends BaseEntity { @PrimaryColumn() messageId: string; @Column() authorId: string; @Column() question: string; @Column("varchar", { arr ...

Draggable element on Angular sidenav slides underneath mat-sidenav-content when dragged

I'm currently working on a project where I need to drag a picture from the mat-sidenav and drop it into the mat-sidenav-content area with the copy function. My initial approach was to simply add the drag functionality to a div element in the sidenav, ...

Easy way to transfer a property value from TypeScript file of one component to another

first-component.ts detailsList=[ { text: value, icon: image }, { text: value, icon: image } ] second-component.html <p>{{detailsList.text}}</p> Can this be easily achieved? ...

Is there a way to determine the number of code lines in all TypeScript files by utilizing tslint?

Looking to retrieve line count of code in all .ts files using tslint? Is there a way to obtain the total line count of code in all .ts files with the help of tslint? I haven't been able to find any information about this feature in the ...

Accessing a specific object in Json Data with multiple objects separated by commas: A quick guide to finding the object

Incorporating ngx-charts, I am successfully plotting some JSON data on a chart like so: app.component.ts: data1 = [ { "name": "DATA1", "series": [ { "name": "ONE", ...

Injecting services with an abstract class is a common practice in Angular library modules

In my development workflow, I have established an Angular Component Library that I deploy using NPM (via Nexus) to various similar projects. This library includes a PageComponent, which contains a FooterComponent and a NavbarComponent. Within the NavbarCom ...

Resolving TypeScript error: Property 'Error' does not exist on type 'Angular2 and Objects'

One of the models I am working with is called "opcionesautocomplete.model.ts" interface IOpcionesAutocomplete { opcionesStyle: OpcionStyle; pcionPropiedades: OpcionPropiedades; } export class OpcionesAutocomplete implements IOpcionesAutocomplet ...

Do arrow functions come highly recommended in Jasmine testing scenarios?

According to the mocha documentation, it is recommended to avoid using arrow functions. Does this same recommendation apply to Jasmine? I could not find any information on this topic in the Jasmine documentation. ...

A guide on showing an image from a JSON file path

As a beginner in Angular, I am currently working with Angular 8. I have a list of image paths stored in the 'dataSource' variable in JSON format, like so: hotdeals: Array(4) 0: {uri: "/Home/HotDeals/hotdeal1.png", id: "2"} 1: {uri: "/Ho ...

Bringing in the Ionic ToastController to a TypeScript class

I'm unsure if it's feasible or wise, but I am currently developing an Ionic 3 project and I want to encapsulate "Toast" functionality within a class so that I can define default values and access it from any part of the application. Is there a ...

Acquiring JSON-formatted data through the oracledb npm package in conjunction with Node.js

I am currently working with oracledb npm to request data in JSON format and here is the select block example I am using: const block = 'BEGIN ' + ':response := PK.getData(:param);' + 'END;'; The block is ...

Setting up next-i18next with NextJS and Typescript

While using the next-i18next library in a NextJS and Typescript project, I came across an issue mentioned at the end of this post. Can anyone provide guidance on how to resolve it? I have shared the code snippets from the files where I have implemented the ...