我从nodejs服务器提供我的index.html。这个ng2文件适用于实时服务器。但是当我从具有特定路由的nodejs index.js加载它时,会出现以下错误。
Uncaught SyntaxError: Unexpected token <
VM105:17Uncaught ReferenceError: System is not defined
我已正确加载文件。以下是加载的文件:
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.33.3/es6-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.16/system-polyfills.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.min.js"></script>
<script src="node_modules/angular2/bundles/angular2.min.js"></script>
<script src="node_modules/angular2/bundles/router.js"></script>
<script src="node_modules/angular2/bundles/http.js"></script>
<!-- 2. Configure SystemJS and Import -->
<script>
System.config({
packages: {
client: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('client/boot')
.then(null, console.error.bind(console));
</script>
我错过了什么?所有文件都是从节点服务器提供的。
答案 0 :(得分:2)
大多数情况下,如果您收到错误Uncaught SyntaxError: Unexpected token <
,则表示script
元素中引用的文件存在404错误。
我认为您的节点服务无法提供您的node_modules
文件夹。因此无法加载node_modules/systemjs/dist/system.src.js
文件(node_modules
中的其他文件也是如此)。