I am trying to attach a backend to my angular 2 application. I have a Server.js file that grabs my index.html but I get an error at my System.import('app').catch(function(err){ console.error(err) }); in my index.html
error
SCRIPt5009: 'System' is undefined
index.html
<html>
<head>
<base href="/">
<title>LGR</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
<link rel="stylesheet" href="./app/css/lgr.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<!-- 1. Load libraries -->
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err) }); <----ERROR HERE!
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>
</html>
server.js
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var app = express();
var path = require('path');
mongoose.connect('mongodb://localhost:27017/LGR_db');
app.use('app', express.static(__dirname + "/app"));
app.use('node_modules', express.static(__dirname + "/node_modules"));
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, '../LGR', 'index.html'));
});
app.listen('3000', function () {
console.log("Server is running on localhost:3000");
});
I am pretty lost here and any help would be great. I guess I don't understand how to "define" system??
edit: added folder structure

Network output

I would say it's because you are sending the index.html file specifically, and doing a static serve for the stuff in /app. If the systemjs.config.js file was in the /app folder and referenced in the index.html as src='/app/systemjs.config.js' it may work.
-- EDIT: Still not 100% sure what the issue is. I did everything we discussed in it and nothing else. Glad it working though!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With