James Amos
James Amos

Reputation: 316

Visual Studio 2017 Typescript baseUrl/paths in tsconfig.json not being recognized

I am using Visual Studio 2017 ASP.NET Core w/ Angular, however when I try to set baseUrl/paths Visual Studio is not recognizing the shortcuts.

Is this due to misconfiguration, or does Visual Studio 2017 not fully support this?

tsconfig.json:

"baseUrl": ".", 
"paths": {
  "@services/*": [ "ClientApp/app/shared/services/*" ] 
}

for the path I've also tried "app/shared/services/*"

import declaration:

import { MyService } from '@services/my.service';

error:

Cannot find module '@services/my.service

Upvotes: 2

Views: 1986

Answers (1)

James Amos
James Amos

Reputation: 316

Nevermind, configuration error. The following was accepted and recognized by Visual Studio.

"baseUrl": "./ClientApp", 
"paths": {
  "@services/*": [ "app/shared/services/*" ]
}

Further to this the resolve section in webpack.config.js needs updating so that webpack also knows how to handle this alias.

resolve: {
    alias: {
        '@services': path.resolve(__dirname, 'ClientApp/app/shared/services')
    },
    extensions: ['.js', '.ts']
},

Upvotes: 3

Related Questions