How to make SystemJS transpile 'typescript' based on file extension without content

I have this SystemJS configuration in index.html:

<body>
        <script src="node_modules/systemjs/dist/system.js"></script>
        <script>
            System.config({
                defaultJSExtensions: true,
                transpiler: 'typescript',
                map: {
                    typescript: 'node_modules/typescript/lib/typescript.js'
                },
                packages: {
                    "ts": {
                        "defaultExtension": "ts"
                    }
                },
            });
            System.import('ts/main');

        </script>
</body>

main.ts:

let a = [1, 2, 3];
let b = [1, 2, 3];

I get: Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode. It looks like the file is not overloaded by SystemJS.

When I add an import statement in the first line, it works fine:

import * as ts from 'typescript'; // or any other package

let a = [1, 2, 3];
let b = [1, 2, 3];

It seems that SystemJS recognizes the typescript file by its “content” - is that right? If so, how to make it overlap every .ts or src / file?

+4
source share
2 answers

As you suspected, systemjs guesses what syntax you use in your file. You can help systemjs by adding

// maybe you need to use " format:'register' " instead
System.config({
  meta: {
    '*.ts': {
      format: 'es6'
    }
  }
});

more module-formats

+5
source

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


All Articles