How to make TypeScript work with SystemJS? (release with .js extension)

I start with the next import in my TypeScript file. Note: the .ts extension implies that I am importing a TypeScript module:

import githubService from './github.service';

This is passed to:

var github_service_1 = require('./github.service');

When SystemJS tries to load this module, it issues the following HTTP command:

GET /github.service

instead of GET /github.service.js. This is clearly not working.

How can I make TypeScript work with SystemJS?

Here is my tsconfig.json file:

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "outDir": "./dist",
        "declaration": false,
        "noImplicitAny": false,
        "removeComments": true,
        "noLib": false,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "sourceMap": true
    },
    "exclude": [
        "node_modules"
    ],
    "compileOnSave": false
}

I also tried changing the option moduleabove to system(changing the format of the generated module from CommonJS to SystemJS), I still get the same problem.

+4
source share
2 answers

, js- . System.js , ".js", System.js index.html :

System.defaultJSExtensions = true;

: defaultJSExtensions

@Naresh, defaultJSExtensions . , , packages config.

, .

+1

tsconfig:

"module": "commonjs",

systemjs, system.

0

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


All Articles