Using systemjs on node.js (& Angular 2)

Let's say I have foo.ts and app.ts as follows:

foo.ts:

export interface Foo { id: number; label: string; }; 

app.ts:

  import {Foo} from './foo' var myfoo: Foo = { "id": 1, "label": "One" }; console.log(JSON.stringify(myfoo)); 

After compilation, the execution of 'node app.js' from the command line is executed as expected if I use "module"="commonjs" in my tsconfig.json . For what I would like to do is use my Foo client interface with Angular 2 and server side with node. Uncomfortably, Angular 2 quickstart, which I am modeling on here , wants "module"="system" in tsconfig.json . This configuration causes an error when trying to run 'node app.js' :

 System.register([], function(exports_1) { ^ ReferenceError: System is not defined` 

I tried following the instructions for using systemjs with node on github , but at this point I just overwrite the keys and can use some help. How can I (a) get my server side app.ts code using systemjs, or in turn, (b) get Angular 2 quick launch using commonjs?

+5
source share
1 answer

I am going to convey this with the answer, even if the question has not been voted. The solution is to use Gulp to compile common typescript code (like the Foo interface) differently for the client ("module" = "system") and the server ("module" = "commonjs"). If there is a way to compile typescript code in OP with "module" = "system", I would like to know anyway. But it seems to be academic, since everyone is managing their project with Gulp or something similar anyway.

+2
source

Source: https://habr.com/ru/post/1238835/


All Articles