简体   繁体   English

Angular2-导入组件时找不到模块

[英]Angular2 - module not being found when imported into component

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安装的,模块Github repo在此处( 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. 似乎该应用程序无法在node_modules文件夹中找到该文件,我不确定为什么。 Here is the relevant section of my Angular2 app.module.ts file: 这是我的Angular2 app.module.ts文件的相关部分:

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'. 我还可以看到,在node_modules文件夹中,模块位于名为“ 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: 我以为这可能是SystemJS配置问题,因此我在config对象的map属性中添加了一行,如下所示:

/**
 * 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 谢谢

I managed to get this working. 我设法使这个工作。 I had forgotten to add an entry into the 'packages' property in the Systemjs.config.js file. 我忘了在Systemjs.config.js文件的'packages'属性中添加一个条目。 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. 如果有人对程序包名称的差异感到困惑,我最终还会使用另一个名为“ ng2-toastr”的烤面包机程序包。

/**
 * 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular2 无法识别来自导入模块的组件 - Angular2 Not Recognizing component From Imported Module angular2使用嵌套导入模块的组件 - angular2 use component of nested imported module 单元测试带有导入模块的angular2组件 - Unit Testing angular2 component with imported module 导入 Angular 功能模块时渲染组件 - Render a Component when a Angular Feature module is imported Angular2/nativeScript:奇怪的错误,抱怨组件未导入任何模块,即使它已导入主模块 - Angular2/nativeScript: Strange error complaining about a component that's not imported into any module even though it is imported in the main module 在core.module上导入的组件上的Angular2链接不起作用 - Angular2 link on component imported on core.module don't work Angular2:模块和组件的区别 - Angular2: Module and Component difference Angular2:行为很奇怪,即使组件未导入到app.module中,也会出现错误提示该组件未导入 - Angular2: Very strange behaviour, error complaining about a component that's not imported even though it is imported in app.module Angular 2 +延迟加载模块被导入的模块覆盖 - Angular 2 + Lazyloaded Module is being overridden by an imported module 角度库模块在未导入的情况下加载 - Angular library module is loaded without being imported
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM