404 Error: @angular/router/bundles/router.umd.js not located

Setting up routing in Angular 2 has been straightforward using the documentation provided on their official website.

Below is an example of how I've imported in my app.component.ts:

import {Component} from '@angular/core';
import {ROUTER_DIRECTIVES} from '@angular/router';

@Component({
  selector: 'my-app',
  templateUrl: 'app/templates/html/app.component.html',
  directives: [ROUTER_DIRECTIVES]
})

export class AppComponent{

}

However, I encountered an error while implementing this setup.

https://i.sstatic.net/yj0tt.png

Upon checking my file structure, I realized that the @angular/router directory does not contain a bundles folder as expected.

https://i.sstatic.net/TLvZ2.png

Could this be a bug? Any insights on how to resolve this issue would be greatly appreciated. Thank you!

Answer №1

This snippet is extracted from your systemjs file.

Start by mapping the ng2 router module, similar to how it is done in your application:

var map = {
    <...>
    '@angular/router':            'node_modules/@angular/router',
    <...>
};

Then, manually set the packIndex for it:

packages['@angular/router'] = { main: 'index.js', defaultExtension: 'js' };

To resolve this issue, customize the code snippet below according to your specific requirements.

Note the various ng2 modules and their versions that you intend to use, as well as your application's name (adjust if necessary):

(function(global) {
    // The map directive informs the System loader where to search for resources
    var map = {
        'YourApp':                    'YourApp', // 'dist',
        '@angular':                   'node_modules/@angular',
        '@angular/router':            'node_modules/@angular/router',
        'rxjs':                       'node_modules/rxjs'
    };
    // The packages directive guides the System loader on loading files without specified filenames and/or extensions
    var packages = {
        'YourApp':                    { main: 'app.js',  defaultExtension: 'js' },
        'rxjs':                       { defaultExtension: 'js' }
    };
    var ngPackageNames = [
        'common',
        'forms',
        'compiler',
        'core',
        'http',
        'platform-browser',
        'platform-browser-dynamic',
        'router-deprecated',
        'upgrade',
    ];
    // For individual files (~300 requests):
    function packIndex(pkgName) {
        packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
    }
    // For bundled files (~40 requests):
    function packUmd(pkgName) {
        packages['@angular/'+pkgName] = { main: 'bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
    }

    packages['@angular/router'] = { main: 'index.js', defaultExtension: 'js' };

    // Most environments should utilize UMD; however, some environments like Karma require individual index files
    var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
    // Include package entries for angular packages
    ngPackageNames.forEach(setPackageConfig);
    var config = {
        map: map,
        packages: packages
    };
    System.config(config);
})(this);

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

Generating a new Observable from a callback function

I am currently working on customizing an example from ngx-chips to fit my specific needs. The challenge I am facing involves adjusting the onRemoving method example provided: public onRemoving(tag: TagModel): Observable<TagModel> { const con ...

How come TypeScript deduces a generic type in a differing manner when a property involving it is present?

I am working on creating a function that takes a props object as input, where the return type of one property serves as a constraint for the arguments of another property. Take a look at the following code snippet: // Defining a base type and another typ ...

"Unlocking Angular event intellisense in Visual Studio Code: A Step-by-Step Guide

Currently, I am enrolled in an Angular course on Udemy. The instructor prefers using VS Code as his code editor, and one interesting feature he showcased was when he tried to add events to a button element. As soon as he opened the parenthesis after the bu ...

Is there a problem with the props being passed? Can someone verify this

Blockquote Having trouble passing props, Parent component: props: { data: { type: Object as PropType<FormatOrderItem>, default: () => {} } I'm facing an issue when trying to pass props from the parent component to the ch ...

Using Angular with Google Maps: Learn how to retrieve a list of markers from a map and implement onClick events for each one

I am currently using the AGM angular module for Angular 2+ to integrate the Google Map API. In my project, I have a directive that displays waypoints as markers on the map using the Google Map Directions Service. Now, I am looking for a way to handle the ...

Leveraging Generics in TypeScript for Creating a Versatile React Component

I developed a versatile React Component that includes several Props capable of accepting a Generic data type. Below is the component in question: export interface MappedObject { key: string; name: string; type: string; status: AppStatus; } export ...

Differences between useFormState and useForm in Next.js version 14

Currently, I am intrigued by the comparison between using the react hook useForm and the react-dom useFormState. The Nextjs documentation suggests utilizing useFormState, but in practice, many developers opt for the react hook useForm. I am grappling with ...

Utilizing RxJs in JavaScript: How to use bindNodeCallback on an Object method that accepts input parameters

Imagine having a class like this: import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/bindNodeCallback'; export class MyClass { name: string; doSomethingWithName(cb: (err) => void) { const err ...

Ngx-toastr - Configure global settings for a particular toast message

Is it possible to define specific global settings for individual toast configurations? I am particularly interested in setting these configurations only for error toasts: { timeOut: 0, extendedTimeOut: 0, closeButton: true } I am aware that I can sp ...

What is the best way to iterate over an Angular HTTP Response?

As a newcomer to Angular, I am working on mastering the process of uploading files and calling an API for validation. The API responds with a list of JSON validation errors based on specific file values. I am currently struggling to iterate through these ...

Ways to transfer information from HTML form components to the Angular class

I am currently working with angular 9 and I have a requirement to connect data entered in HTML forms to the corresponding fields in my Angular class. Below is the structure of my Angular class: export interface MyData { field1: string, textArea1 ...

Adding or removing an event listener for a document in Angular 2, without using the constructor

In my current project, I implemented a popup component with a movable template feature. The popup opens when the open() method is triggered and attaches movable listeners; then, it closes upon calling the close() method, but the listeners do not get remove ...

Error encountered in React component: TypeScript TS2339 states that the property 'xyz' is not found on type 'IntrinsicAttributes...'

I am attempting to develop a straightforward React component that can accept any properties. The syntax below using any is causing issues (unexpected token just before <): export class ValidatedInput extends React.Component<any, any> {...} The p ...

Passing a value to a property with a dynamically passed name in TypeScript

I'm encountering an eslint/typescript error message: errorUnsafe member access .value on an any value @typescript-eslint/no-unsafe-member-access when attempting to assign a value to a dynamically named property: selectChange(name: string, value: stri ...

The lazy loading feature is affected by Angular's ng build process

My app has lazy loading configured and works fine with ng serve. However, when I use ng build, it stops working without any error messages. I have checked the Angular official documentation and can't seem to find any missing steps in my process. I in ...

Angular 2 Final Router Encounters Error

I have implemented a basic router in my application to accommodate a URL structure like www.myhost.com/mission/myguid. I have reviewed the tutorials on the Angular site, but I haven't found any discrepancies. The "normal" routes such as www.myhost.com ...

Angular's navigation system also includes encoding for special characters such as question marks (?) and equal signs

When using Angular to navigate to a page and passing a returnUrl as a parameter, I follow this approach: this.router.navigate(['/validation'], { queryParams: { returnUrl: state.url }}); However, the resulting URL looks like this: https://myhost/ ...

Encountering an issue when attempting to integrate material-ui into the jhipster project

After creating a jhipster application which utilizes Angular as the front end UI framework, I am encountering issues with the versions of jhipster and node as specified below: jhipster: 7.9.3, npm: '9.6.5', node: '18.16.0', My objectiv ...

Injectable Angular Reactive Form

I've encountered an issue with a utility component I developed called the "error display component." This component is designed to handle errors in a generic way. export class ShowErrorComponent { // path refering to the form-element @Input(&apos ...

Leverage the SVG foreignObject Tag within your Angular 7 project

I am currently working with Angular 7 and trying to use the SVG foreignObject to embed some HTML code. However, I am encountering an issue where Angular fails to recognize the HTML tags and throws an error in the terminal. Below is the code snippet: &l ...