[英]Systemjs and tsc setup - *.ts.js 404 (Not Found) Error
我只是想用最少的设置创建概念验证的TS + SystemJS项目-没有“ Angular2入门工具包”之类的东西。 我花了一个小时来搜索和调整此设置,但仍然无法正常工作。
我有以下设置:
/src/
- model.ts
- bootstrap.ts
/dist/
tsconfig.json
system.config.js
index.html
我的tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"sourceMap": true,
"removeComments": false,
"outDir": "./dist/"
},
"filesGlob": [
"./src/**/*.ts"
],
"compileOnSave": true
}
我的SystemJS配置
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
map: {
testapp: './src'
},
baseURL: './src',
packages: {
testapp: {
format: 'register',
defaultExtension: 'js'
}
},
});
我的index.html
<script src="/node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="/node_modules/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System.import('bootstrap.ts')
.then(function(app) {
console.log('app bootstrap success!');
}, console.error.bind(console));
</script>
最后,控制台中出现以下错误:
system.src.js:1051 GET http://0.0.0.0:8080/src/bootstrap.ts.js 404 (Not Found)fetchTextFromURL @ system.src.js:1051....
Error: (SystemJS) XHR error (404 Not Found) loading
我在一个终端选项卡中运行tsc -w
在另一个终端选项卡中运行简单的https服务器。
显然-SystemJS希望使用扩展名为.ts.js的文件,而tsc生成.js和源映射,而不要使用.ts.js 。
我怀念webpack
或gulp
来完成这项工作的某些部分? 我以为SystemJS和tsc
可以进行捆绑和编译,但是显然在构建过程中缺少一些东西。 对SystemJS设置进行解释,而不是修复bug也会很有帮助。
可以通过以下方法修复安装程序:
1)正如@Nitzan Tommer提到的那样- 在System.import块中将.ts更改为.js
index.html: System.import('bootstrap.js')
2) (SystemJS)require未定义 , 此错误已解决-更改tsconfig.json以将“ system”作为模块
{
"compilerOptions": {
"module": "system",
"target": "es5",
//..
这是我使用此设置创建的演示仓库: https : //github.com/shershen08/systemjs-typescript-simple
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.