首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular2 -导入组件时找不到模块

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

Stack Overflow用户
提问于 2017-01-11 15:11:16
回答 1查看 835关注 0票数 1

我有一个问题,而我打算在我的应用程序中使用的一个模块是找不到的。我得到以下错误:

代码语言:javascript
复制
 GET http://product-admin.dev/node_modules/angular2-toaster/ 404 (Not Found)

该模块是使用NPM安装的,模块Github就在这里(https://github.com/Stabzs/Angular2-Toaster)。

代码语言:javascript
复制
npm install angular2-toaster

似乎应用程序无法在node_modules文件夹中找到该文件,我不知道原因。下面是我的Angular2 app.module.ts文件的相关部分:

代码语言:javascript
复制
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

我还可以看到,在node_modules文件夹中,模块在一个名为‘angular2-烤面包机’的文件夹中。我想这可能是一个SystemJS配置问题,所以我在config对象的map属性中添加了一行,如下所示:

代码语言:javascript
复制
/**
 * 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"
        },

这似乎也没有什么区别。有人知道为什么会发生这个问题吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-11 16:41:53

我成功地完成了这个任务。我忘了在Systemjs.config.js文件中的“packages”属性中添加一个条目。这是修改后的档案,现在可以用了。我还使用了一个不同的烤面包包,叫做“NG2-烤面包”,如果有人对包名的不同感到困惑的话。

代码语言:javascript
复制
/**
 * 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);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41594355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档