Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using systemjs on node.js (& Angular 2)

Say I have a 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 compiling, executing 'node app.js' from the command line runs as expected if I use "module"="commonjs" in my tsconfig.json. Cutting to the chase, what I would like to do is is use my Foo interface client-side with Angular 2, and server-side with node. Inconveniently, the Angular 2 quickstart 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 have tried following the instructions for using systemjs with node on github, but at this point I am just mashing keys and could use some help. How do I either (a) get my app.ts code running on the server-side using systemjs, or alternately, (b) get the Angular 2 quickstart running with commonjs?

like image 665
Ken Avatar asked Oct 30 '22 12:10

Ken


1 Answers

I am going to wrap this up with an answer, even if the question hasn't been up-voted. The solution appears to be to use Gulp to compile the common typescript code (like interface Foo) differently for the client ("module"="system") and the server ("module"="commonjs"). If there is a way to compile the typescript code in the OP with "module"="system" I'd still like to know. But it appears to be kind of academic since everyone manages their project with Gulp or something similar anyway.

like image 118
Ken Avatar answered Nov 10 '22 13:11

Ken