I'm trying to build a boilerplate template to bootstrap angular 2 applications using express, angular 2, typescript, gulp, and systemjs. For some reason, my index.html file won't recognize my bootstrap.js file. All my jade and typescript is located in src. I'm using gulp to transpile typescript from src to dist, and serving my static assets from node_modules and jspm_packages in express. But when it finally comes time to invoke System.import, like so:
System.import('app').catch(console.error.bind(console)),
i get:
Error: SyntaxError: Unexpected token <
Evaluating http://localhost:3000/app/bootstrap.js
Error loading http://localhost:3000/app/bootstrap.js
The error seems to be caused in angular2-polyfills.min.js.
Here is my basic express backend to give you an idea of how my assets and files are served up (I'm suspicious that i'm having a temporary brainfart and my paths are off):
const app = express();
app.use('/jspm_packages', express.static('jspm_packages'));
app.use('/node_modules', express.static('node_modules'));
app.get('*', function(req, res) {
const file = fs.readFileSync('src/index.jade').toString();
const html = jade.render(file);
return res.send(html);
});
app.listen(process.env.PORT || 3000);
My index.html file is located in dist, the directory that holds all transpiled javascript. Here is the packages property on my System.config:
packages: {
"dist": {
"main": "bootstrap",
"format": "system",
"defaultExtension": "js"
}
},
I was under the impression that dist identifies the folder relative to the BASE_URL (which in my case is just /), and the main property identifies the file name. So I thought that by calling System.import('app'), it will look inside the app folder inside dist and find the bootstrap.js file to bootstrap my angular2 app, but that doesn't seem to be the case. When i open my up chrome console, bootstrap.js doesnt show up in my sources, so I'm guessing theres a path error somewhere, but I've tried every variation and can't seem to get it to work.
Any help would be greatly appreciated, thanks.
Update:
Here is my index.html: https://jsfiddle.net/r02r3jk3/
Here is the folder structure and server-side code that serves up content: https://jsfiddle.net/cejk0jw3/
When I inspect the network Tab for the response to the request for the browser.js file in angular2/platform, I get the following:
The request URL is http://localhost:3000/jspm_packages/npm/angular2@2.0.0-beta.9/platform/browser.js
The response has a content-type of Content-Type:text/html; charset=utf-8 but the response is my index.html file :(