Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript with system.js module running in node error

Tags:

typescript

I would like to use the system.js module manager with TypeScript. My plan is to run typescript in node

The problem is that, if i mark my Main.js (generated from Main.ts) file as the entry point, it will crash with this error:

ReferenceError: System is not defined

And it's normal, because my generated code start like this: System.register(["./Apple"], function(exports_1) {

And for sure, there is no System class in node by default. So how to make typescript or node to load the system.js module?

I can create an extra js file to load it with require, but i'm looking for a native solution inside typescript

Thanks!

like image 498
Grosmar Avatar asked Sep 07 '15 20:09

Grosmar


People also ask

How do I resolve a node module error?

To fix the Cannot find module error, simply install the missing modules using npm . This will install the project's dependencies into your project so that you can use them. Sometimes, this might still not resolve it for you. In this case, you'll want to just delete your node_modules folder and lock file ( package-lock.

Is TypeScript compatible with Nodejs?

TypeScript is well-established in the Node. js world and used by many companies, open-source projects, tools and frameworks. Some of the notable examples of open-source projects using TypeScript are: NestJS - robust and fully-featured framework that makes creating scalable and well-architected systems easy and pleasant.

What module system does TypeScript use?

TypeScript offers support for creating and using modules with a unified syntax that is similar to the ES Module syntax, while allowing the developer to output code that targets different module loaders, like Node. js (CommonJS), require. js (AMD), UMD, SystemJS, or ECMAScript 2015 native modules (ES6).


1 Answers

You should tell the compiler to export your modules into commonjs and not systemjs. Node is using commonjs as its native module system.

like image 187
gilamran Avatar answered Nov 28 '22 10:11

gilamran