2016-12-14 24 views
1

我正在使用mockBackend作爲我的Angular2應用程序的一部分,以便測試我正在使用的登錄組件。我有一個獨立版本的登錄工作。但是,當我嘗試將其納入我的已開發應用程序時,我遇到了一個問題。具體來說,似乎在編譯時,我的一些文件被放入「dist」文件夾中,使Angular無法找到它們。不知道爲什麼會這樣。下面是我在控制檯中看到的錯誤:被放置在「Dist」文件夾中的文件被錯誤放置,打破了Angular 2應用程序

http://localhost:3000/node_modules/@angular/http/bundles/http.umd.js/testing 404 (Not Found) 

果然,當我看着在我的「測距」文件我node_modules,我看到了「測試」文件夾中是存在的,但它不是正是角的尋找它。

幾個星期前,我認爲是一個類似的問題,與我的socket.io「dist」位置,我不得不手動調整我的systemjs.config.js文件指向正確的位置。然後它工作。在這種情況下,那是我需要再做的事情嗎?當編譯到「dist」文件夾時出現這樣的錯誤位置時,我該如何最好地處理它?

順便說一句,我目前正在使用Angular 2.0.0。

這裏是我的systemjs.config.js的內容是什麼樣子:

/** 
* SystemJS configuration file. 
*/ 
(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: 'dist', 
      // 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/material.umd.js',*/ 
      // other libraries 
      'rxjs': 'npm:rxjs', 
      'angular2-in-memory-web-api': 'npm:angular2-in-memory-web-api', 
      // 'socket.io-client': 'npm:/socket.io-client/socket.io.js', 
      'socket.io-client': 'node_modules/socket.io/node_modules/socket.io-client/socket.io.js', 
      // 'socket.io-client': 'dist/node_modules/socket.io/node_modules/socket.io-client/socket.io.js', 
      'angular2-chartjs': 'npm:angular2-chartjs', 
      'chart.js': 'npm:chart.js/dist/Chart.bundle.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'}, 
      'socket.io-client': {'defaultExtension': 'js'}, 
      'angular2-chartjs': {main: './dist/index.js', defaultExtension: 'js'} 
     } 
    }); 
})(this); 

而且這裏是我的package.json:

{ 
    "name": "abc", 
    "version": "0.0.1", 
    "scripts": { 
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ", 
    "lite": "lite-server", 
    "postinstall": "typings install", 
    "tsc": "tsc", 
    "tsc:w": "tsc -w", 
    "typings": "typings", 
    "docs": "typedoc --experimentalDecorators --out docs/ app/ --target 'es5' -module 'system' --ignoreCompilerErrors", 
    "clean": "del /q dist", 
    "browserify": "^13.0.1", 
    "uglifyjs": "^2.4.10", 
    "minify": "uglifyjs dist/main.min.js --screw-ie8 --compress --mangle --output dist/main.min.js", 
    "build": "npm run clean && tsc", 
    "build_prod": "npm run build && browserify -s main dist/main.js > dist/main.min.js && npm run minify" 
    }, 
    "license": "ISC", 
    "dependencies": { 
    "@angular/common": "^2.0.0", 
    "@angular/compiler": "^2.0.0", 
    "@angular/core": "^2.0.0", 
    "@angular/forms": "^2.0.0", 
    "@angular/http": "^2.0.0", 
    "@angular/platform-browser": "^2.0.0", 
    "@angular/platform-browser-dynamic": "^2.0.0", 
    "@angular/router": "^3.0.0", 
    "angular-in-memory-web-api": "~0.1.15", 
    "angular2-chartjs": "^0.1.6", 
    "bootstrap": "^3.3.6", 
    "core-js": "^2.4.1", 
    "ng2-charts": "^1.4.1", 
    "reflect-metadata": "^0.1.3", 
    "rxjs": "5.0.0-beta.12", 
    "socket.io-client": "^1.4.8", 
    "systemjs": "0.19.27", 
    "zone.js": "^0.6.23" 
    }, 
    "devDependencies": { 
    "browserify": "^13.0.1", 
    "concurrently": "^2.2.0", 
    "jasmine-core": "^2.5.2", 
    "karma": "^1.3.0", 
    "karma-chrome-launcher": "^2.0.0", 
    "karma-jasmine": "^1.0.2", 
    "lite-server": "^2.2.2", 
    "typescript": "^2.0.2", 
    "typings": "^1.3.2", 
    "uglifyjs": "^2.4.10" 
    } 
} 

回答

1

於是我找到了一個解決方案。我不得不此行手動添加到我的systemjs.config.js文件:

「@角/ HTTP /測試」:'npm:@angular/http/bundles/http-testing.umd.js'

在那之後,一切都按預期。

相關問題