Home Ask Login Register

Developers Planet

Your answer is one click away!

Gustav February 2016

is it possible to have multiple modules defined in tsconfig?

Ok, so I'm making a angular2 app with a node server. I've followed the 5min tutorial so I'm using "system" as the module system. However I am using a simple node express server instead of the way they have in the tutorial. I am writing this in typescript as well, but it is also compiled to "system" style of importing modules. And when running the server I get System is not defined.

  • How do I fix so System is defined when starting the server?
  • Is it not recommended to use "system" as the compiler option "module" in the tsconfig-file, when writing a node server?
  • Can I compile the server code with eg "commonjs" and the angular front end with "system"?
  • How do I do the configuration of module loading (the small script they have in the index.html) if I would not use "system" in the front end either?


Thierry Templier February 2016

I would recommend to split front-end and back-end applications into different projects and make them communicate through a REST service. I mean the server application will provide the service and the front application will consume it using AJAX.

This way you will be sure that there won't be conflict between the tools you use. For example the use or not of SystemJS. You'll be free to use SystemJS in the Angular2 application as described in the 5min tutorial of the angular.io website and commonjs for the Node / Express application.

The following article describes how to do that:

Vlado Tesanovic February 2016

As @Thierry Templier suggested, you need to split your code into /client and /server to be more maintainable and structured, if you didn't do that yet.

You can create two tsconfig.json files, put one into /server and other into /client folder.

  • /server
    • tsconfig.json ( with module: commonjs )
  • /client
    • tsconfig.json ( with module: systemjs )

When you are invoking tsc from shell, you use --project command:

tsc -p ./server <-- /server/tsconfig.json is loaded
tsc -p ./client <-- /client/tsconfig.json is loaded

Post Status

Asked in February 2016
Viewed 2,531 times
Voted 9
Answered 2 times


Leave an answer

Quote of the day: live life