Angular2 - module not being found when imported into component

871 views Asked by At

I am having a problem whereas a module I am intending to use in my application is not being found. I get the following error:

 GET http://product-admin.dev/node_modules/angular2-toaster/ 404 (Not Found)

The module is installed using NPM and the module Github repo is here (https://github.com/Stabzs/Angular2-Toaster).

npm install angular2-toaster

It seems that the application is not able to find the file within the node_modules folder and I am not sure why. Here is the relevant section of my Angular2 app.module.ts file:

import { FileUploaderDirective } from "./components/directives/files/FileUploaderDirective";
import { TabsDirective } from "./components/directives/tabs/TabsDirective";
import { PaginationDirective } from "./components/directives/pagination/PaginationDirective";

import { APIUrlPipe } from "./pipes/apiurl.pipe";
import { ToasterModule } from "angular2-toaster";


@NgModule({
    imports: [
        BrowserModule,
        HttpModule,
        FormsModule,
        routing,
        ToasterModule,
        ReactiveFormsModule

I can also see that within the node_modules folder the module is in there in a folder called 'angular2-toaster'. I was thinking this may be a SystemJS config issue so I added in a line to the map property of the config object as shown here:

/**
 * System configuration for Angular 2 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',
            // other libraries
            'rxjs'                       : 'npm:rxjs',
            'angular2-toaster'           : 'npm:angular2-toaster',
            'angular2-in-memory-web-api' : 'npm:angular2-in-memory-web-api',
            "angular2-jwt"               : "npm:angular2-jwt/angular2-jwt.js"
        },

This doesn't seem to have made any difference either. Can anyone see why this problem is happening?

Thanks

1

There are 1 answers

0
James On BEST ANSWER

I managed to get this working. I had forgotten to add an entry into the 'packages' property in the Systemjs.config.js file. Here is that file amended and now working. I also ended up using a different toaster package called 'ng2-toastr' if anyone is confused by the difference in package names.

/**
 * System configuration for Angular 2 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',
            // other libraries
            'rxjs'                       : 'npm:rxjs',
            'ng2-toastr'                 : 'npm:ng2-toastr',
            'angular2-in-memory-web-api' : 'npm:angular2-in-memory-web-api',
            "angular2-jwt"               : "npm:angular2-jwt/angular2-jwt.js"
        },
        // 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'
            },
            'angular2-in-memory-web-api': {
                main: './index.js',
                defaultExtension: 'js'
            },
            'angular2-jwt': {
                'defaultExtension': 'js'
            },
            'npm:ng2-toastr': {
                main: './ng2-toastr.js',
                defaultExtension: 'js'
            }
        }
    });
})(this);