Angular2 - 导入组件时找不到模块
Angular2 - module not being found when imported into component
我遇到了一个问题,但找不到我打算在我的应用程序中使用的模块。我收到以下错误:
GET http://product-admin.dev/node_modules/angular2-toaster/ 404 (Not Found)
该模块是使用 NPM 安装的,模块 Github 存储库位于此处 (https://github.com/Stabzs/Angular2-Toaster)。
npm install angular2-toaster
应用程序似乎无法在 node_modules 文件夹中找到文件,我不确定为什么。这是我的 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
我还可以看到,在 node_modules 文件夹中,模块位于名为 'angular2-toaster' 的文件夹中。我在想这可能是一个 SystemJS 配置问题,所以我在配置对象的映射 属性 中添加了一行,如下所示:
/**
* 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"
},
这似乎也没有任何区别。谁能看出为什么会出现这个问题?
谢谢
我设法让它工作了。我忘记在 Systemjs.config.js 文件的 'packages' 属性 中添加一个条目。这是修改后的文件,现在可以使用了。如果有人对包名称的差异感到困惑,我最终还使用了另一个名为 '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);
我遇到了一个问题,但找不到我打算在我的应用程序中使用的模块。我收到以下错误:
GET http://product-admin.dev/node_modules/angular2-toaster/ 404 (Not Found)
该模块是使用 NPM 安装的,模块 Github 存储库位于此处 (https://github.com/Stabzs/Angular2-Toaster)。
npm install angular2-toaster
应用程序似乎无法在 node_modules 文件夹中找到文件,我不确定为什么。这是我的 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
我还可以看到,在 node_modules 文件夹中,模块位于名为 'angular2-toaster' 的文件夹中。我在想这可能是一个 SystemJS 配置问题,所以我在配置对象的映射 属性 中添加了一行,如下所示:
/**
* 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"
},
这似乎也没有任何区别。谁能看出为什么会出现这个问题?
谢谢
我设法让它工作了。我忘记在 Systemjs.config.js 文件的 'packages' 属性 中添加一个条目。这是修改后的文件,现在可以使用了。如果有人对包名称的差异感到困惑,我最终还使用了另一个名为 '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);