Velidan Velidan - 1 month ago 6
TypeScript Question

typescript can't find module for system.js alias

I am working with angular2 and when I created some aliases to modules via System.js (for example)

map: {
'%cool_modules%' : prodFolderName + '/modules',
}


and when I tried to import {MyModule} from '%cool_modules%', I got an error about: typescript: can't find module %cool_modules%

The same for @angular/core , rx/Obserable erc.

Is it possible to fix it? Thanks

Answer

You need to edit your tsconfig.json to recognize your alias:

{
    "compilerOptions": {
        ...
        "paths": {
            "@angular/core": [
                "jspm_packages/npm/@angular/core@2.0.1"
            ],
            "rxjs/*": [
                "jspm_packages/npm/rxjs@5.0.0-beta.12/*"
            ],
            "systemjs": [
                "jspm_packages/npm/systemjs@0.19.38"
            ],
            "zone.js": [
                "jspm_packages/npm/zone.js@0.6.12"
            ],
            "%cool_modules%": [
                "coolModulePath"
            ]
        }
    }
}
Comments