KESO KESO - 2 months ago 61x
Javascript Question

Angular2 - System is not defined when using out angular-cli

I have been working with angular-cli to create a sample project, understanding that this tool is just for compiling and generating an embebed server for test.
However when I open the files inside dist folder without any server but the browser, I got many problems because it can get the files, specially this message:

ReferenceError: System is not defined

If I try to open the project using tomcat for example I see this:

Then I tried to rewrite manually the directories to get these files and then I got this:

Inside the index.html

System.import('system-config.js').then(function () {

I can keep rewriting... but then I got more and more errors for the same reason.
So I don't have any clue how to solve this and I can't find a good example.

I can't depend of a Node server and since this is just JavaScript code for the side client it should be work even without any server.

I would apreciate any suggest or idea.

EDIT: I have tried
ng serve
and that is how I know the app works, but I need to use it in other server like tomcat.


Finally I solved this as I was expecting, using a CDN. I took as base the example from Angular documentation:

var  map = {
'app':                        'app',
'@angular':                   '', // sufficient if we didn't pin the version
'@angular/router':            '' + routerVer,
'@angular/forms':             '' + formsVer,
'@angular/router-deprecated': '' + routerDeprecatedVer,
'angular2-in-memory-web-api': '', // get latest
'rxjs':                       '',
'ts':                         '',
'typescript':                 ''

This is from the system config file.
Using it this way now I can open my project using tomcat or another application server or even just from the web browser. Thank you for all the good ideas.