TypeScript with system.js module running in node error

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 the Main.js file (generated from Main.ts) as an entry point, it will crash with this error:

ReferenceError: system not defined

And this is normal, because my generated code starts as follows: System.register (["./Apple"], function (exports_1) {

And, of course, by default, the node class does not have a System class. So how to make typescript or node to load the system.js module?

I can create an additional js file to load it with the requirement, but I'm looking for my own solution inside typescript

Thanks!

+4
source share
3 answers

You must tell the compiler to export your modules to commonjs, not systemjs. Node uses commonjs as its own modular system.

+2
source

I might not get it right, but you tried to follow the section node.json the system.jsGitHub Readme ( https://github.com/systemjs/systemjs )

$ npm install systemjs

then

var System = require('systemjs');

// loads './app.js' from the current directory
System.import('./app').then(function(m) {
  console.log(m);
});

Hope this helps.

0
source

Are you using the tsconfig file? You added a module: 'system' I encountered a similar problem, this fixed this. Also make sure system.src.js is at the top of the scripts.

0
source

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


All Articles