2016-02-05 78 views
4

當我玩Angular 2時,系統JS有一個奇怪的問題。系統JS不加載模塊

一切工作正常,但似乎隨機系統JS無法找到模塊了.. 。

我收到此錯誤信息:

GET http://localhost:9000/angular2/platform/browser.js 404 (Not Found) @ system.src.js:4891(anonymous function) @ system.src.js:4891 
GET http://localhost:9000/angular2/core.js 404 (Not Found) @ system.src.js:4891 
GET http://localhost:9000/angular2/router.js 404 (Not Found) @ system.src.js:4891 
GET http://localhost:9000/angular2/http.js 404 (Not Found) @ system.src.js:4891 
GET http://localhost:9000/angular2/core.js 404 (Not Found) @ system.src.js:4891 
GET http://localhost:9000/angular2/http.js 404 (Not Found) @ system.src.js:4891 
GET http://localhost:9000/angular2/src/facade/lang.js 404 (Not Found) @ system.src.js:4891 
GET http://localhost:9000/angular2/router.js 404 (Not Found) @ system.src.js:4891 

有時它更有時是錯誤更少......

最奇怪的是,等待了一會兒,tryi後ng一遍又一遍刷新頁面,該應用程序神奇地再次開始工作!

我使用[email protected][email protected](最新在當時)。

腳本中的index.html與SystemJS配置部分是這樣的:

<script src="./node_modules/angular2/bundles/angular2-polyfills.js"></script> 
<script src="./node_modules/es6-shim/es6-shim.min.js"></script> 
<script src="./node_modules/systemjs/dist/system.js"></script> 
<script> 
    //configure system loader 
    System.config({ 
    defaultJSExtensions: true 
    }); 
    //bootstrap the Angular2 application 
    System.import('dist/app').catch(console.log.bind(console)); 
</script> 
<script src="./node_modules/rxjs/bundles/Rx.js"></script> 
<script src="./node_modules/angular2/bundles/angular2.dev.js"></script> 
<script src="./node_modules/angular2/bundles/http.dev.js"></script> 
<script src="./node_modules/angular2/bundles/router.dev.js"></script> 

任何人都認識這個問題?

謝謝!

+2

這將是很好,如果你可以分享你的systemjs配置 –

+0

同意@Vldao。沒有這個,我們只能嘗試猜測;-) –

+0

我已經添加了配置。 – mottosson

回答

0

看來你SystemJS是不正確的:

你使用類似的東西在你的HTML登錄頁面:

<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script> 
<script src="node_modules/systemjs/dist/system.src.js"></script> 
<script src="node_modules/rxjs/bundles/Rx.js"></script> 
<script src="node_modules/angular2/bundles/angular2.dev.js"></script> 
<script src="node_modules/angular2/bundles/router.dev.js"></script> 
<script src="node_modules/angular2/bundles/http.dev.js"></script> 

<script> 
    System.config({ 
    packages: {   
     app: { 
     format: 'register', 
     defaultExtension: 'js' 
     } 
    } 
    }); 
    System.import('app/boot') 
     .then(null, console.error.bind(console)); 
</script> 

從我在你的HTTP調用看到,我想有是類似於你的SystemJS配置:

System.config({ 
    packages: {   
     app: { 
     format: 'register', 
     defaultExtension: 'js' 
     }, 
     angular2: { 
     format: 'register', 
     defaultExtension: 'js' 
     } 
    } 
    }); 
+0

那麼正確的方法是什麼? (我有類似的問題) – shershen

0

也許是一個遠射,因爲我沒有足夠的權限評論和要求更多的信息。你有沒有嘗試檢查文件app.ts實際上是否在dist/app