系统JS不加载模块
问题描述:
当我玩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>
任何人都认识这个问题?
谢谢!
答
看来你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
答
也许是一个远射,因为我没有足够的权限评论和要求更多的信息。你有没有尝试检查文件app.ts
实际上是否在dist/app
?
这将是很好,如果你可以分享你的systemjs配置 –
同意@Vldao。没有这个,我们只能尝试猜测;-) –
我已经添加了配置。 – mottosson