Angular2与NodeJS和Typescript错误

时间:2016-06-28 11:06:16

标签: node.js typescript angular systemjs

我试图在Angular2,NodeJS和TypeScript中设置一个简单的应用程序,但是在实例化Angular2应用程序错误时遇到错误。我收到以下错误:

es6-shim.js:1 Uncaught SyntaxError: Unexpected token <
angular2-polyfills.js:1 Uncaught SyntaxError: Unexpected token <
system.src.js:1 Uncaught SyntaxError: Unexpected token <
Rx.js:1 Uncaught SyntaxError: Unexpected token <
angular2.dev.js:1 Uncaught SyntaxError: Unexpected token <
http.dev.js:2 Uncaught ReferenceError: System is not defined(anonymous function) @ http.dev.js:2
(index):15 Uncaught ReferenceError: System is not defined

我不确定为什么会这样?我的index.html文件似乎是一个问题,它调用所有Angular2脚本依赖项,然后实例化SystemJS功能。这是该文件:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Angular 2 Quick Start</title>
<base href="/"/>
<script src="../node_modules/es6-shim/es6-shim.js"></script>
<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="https://code.angularjs.org/2.0.0-beta.0/http.dev.js"></script>

    <script>
        System.config({
            packages: {
                app: {
                    format: 'register',
                    defaultExtension: 'js'
                }
            }
        });
        System.import('app/app')
                .then(null, console.error.bind(console));
    </script>
</head>
<body>
<my-app>Loading...</my-app>
</body>
</html>

与index.html文件相关的我的app.ts文件位于名为app的文件夹中,所以这是正确的。

任何人都可以解释为什么我会收到这个错误吗?我在想它可能是一个SystemJS错误,但我无法解决这个问题!

这是文件结构的图片。

enter image description here

这是我的NodeJS入口点文件:

var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var logger = require('morgan');
var port = process.env.PORT || 3006;
var app = express();
// view engine setup
app.set('views', path.join('./client'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use('/app', express.static(path.resolve(__dirname, 'app')));
app.use('/libs', express.static(path.resolve(__dirname, 'libs')));
var renderIndex = function (req, res) {
    res.sendFile(path.resolve('./client/index.html'));
};
app.get('/*', renderIndex);
var server = app.listen(port, function () {
    var host = server.address().address;
    var port = server.address().port;
    console.log('This express app is listening on port:' + port);
});

由于

0 个答案:

没有答案