2017-03-26 19 views
0

我正在從Angular 2 quickstart中嘗試添加第三方組件(特定於ng2-split-pane)。我與故宮安裝了它,並根據它的plunkr例子,我有以下systemjs.config.js:無法通過npm使用外部angular2模塊

(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', 
     '@angular/material': 'npm:@angular/material/bundles/material.umd.js', 

     // other libraries 
     'rxjs':      'npm:rxjs', 
     'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js', 
     'autobahn':   'npm:@types/autobahn/index.d.ts', 
     'ng2-split-pane': 'npm:ng2-split-pane/lib/ng2-split-pane.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' 
     } 
    } 
    }); 
})(this); 

及以下app.module.ts:

import { NgModule }  from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 

import { AppComponent } from './app.component'; 
import { MaterialModule } from '@angular/material'; 
import { BattleLogComponent } from './battlelog.component'; 
import { SplitPaneModule } from 'ng2-split-pane'; 

@NgModule({ 
    imports:  [ BrowserModule, MaterialModule, SplitPaneModule ], 
    declarations: [ AppComponent, BattleLogComponent ], 
    bootstrap: [ AppComponent ] 
}) 
export class AppModule { } 

但我只是得到一個錯誤,說「app/app.module.ts(7,33):錯誤TS2307:找不到模塊'ng2-split-pane'。」

我可以加載其他東西(例如材料)很好,我在這裏錯過了什麼?

編輯:目錄結構(最node_modules省略空間):

. 
├── app 
│   ├── app.component.ts 
│   ├── app.module.ts 
│   ├── app.ng.css 
│   ├── app.ng.html 
│   ├── autobahn.service.ts 
│   ├── battlelog.component.ts 
│   ├── battlelog.ng.html 
│   └── main.ts 
├── favicon.ico 
├── index.html 
├── js 
│   └── autobahn.min.js 
├── LICENSE 
├── node_modules 
│   ├── mkdirp 
│   ├── moment 
│   ├── ms 
│   ├── negotiator 
│   ├── ng2-split-pane 
│   ├── node-uuid 
│   ├── nopt 
├── package.json 
├── styles.css 
├── systemjs.config.extras.js 
├── systemjs.config.js 
├── tsconfig.json 
└── tslint.json 
+0

ng2-split-pane是否出現在您的node_modules文件夾中? –

+0

是的 - 我驗證了node_modules/ng2-split-pane/lib/ng2-split-pane.js存在並且具有SplitPaneModule的導出。 – estick

+0

您的項目中的node_modules文件夾在哪裏?我們可以得到目錄樹嗎? –

回答

0

我能得到這個具有角-CLI通過使用明確說明NG2-拆分窗格的位置工作:

import { SplitPaneModule } from '../../node_modules/ng2-split-pane/src/ng2-split-pane'; 
+0

所以實際上,雖然編譯它現在無法加載資源,當我嘗試運行頁面: :3000/node_modules/ng2-split-pane/src/ng2-split-pane無法加載資源:服務器響應狀態爲404(未找到) – estick

+0

嗯,這可能是任何數量的路徑相關的問題。除非你非常依賴'systemjs',否則我會嘗試在安裝完成後使用總是可愛的'angular-cli'重新啓動應用程序:https://github.com/angular/angular-cli#installation(它使用webpack)在你最喜歡的終端仿真器中'ng new someApplication'並重新嘗試安裝'ng2-split-pane'。祝你好運! –