I'm trying to create typescript server side (example code import mongoose from 'mongoose';
) and I know I'm supposed to get systemjs initialized before, but I don't know how to in a server side script.
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
If you want to use module 'system' at server side - you will have to install systemjs package and configure it:
import System = require('systemjs');
System.config({
...
});
System.import(...);
But in my opinion it would be better to target commonjs and run it 'natively' in node.js without any extra dependencies.
As a bonus - you can also run commonjs module in browser using systemjs as loader - it supports loading them out of the box.
[EDIT]
Note that node.js is build with commonjs as module standard. Therefore you can consume 'system' modules using SystemJS but only 'inside' your main program that must be in commonjs format to be able to run in nodejs.