Visual Studio Code can't resolve angular's tsconfig paths











up vote
0
down vote

favorite












I'm trying to import some services using barrels and tsconfigs paths options but I can't get angular and vscode to get along.



If it works for one it doesn't for the other and viceversa...



My situation seems to be pretty simple:




  • in src/app/services I have a service which is exported in a index.ts

  • my src/tsconfig.app.json is just this:




{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"types": ,
"baseUrl": ".",
"paths": {
"services": ["app/services"]
}
},
"exclude": [
"test.ts",
"**/*.spec.ts"
],
}


and my angular app compiles with no issues, but vscode keep giving me errors every time I try to import my service from 'services' giving me [ts] Cannot find module 'services'.



why?



I'm using typescript 3.1.6 and in vscode settings I have "typescript.tsdk": "C:/Users/myuser/AppData/Roaming/npm/node_modules/typescript/lib" (I also tried to leave the default setting, no changes)





edit:



if I specify paths in ./tsconfig.json starting from src, vscode is happy but angular is not.



if I specify paths in both tsconfig.json and src/tsconfig.app.json, both vscode and angular are happy, but it seems a too stupid workaround to me...










share|improve this question
























  • And did you try setting the TSDK to your project instead of the NPM one ?
    – trichetriche
    Nov 6 at 14:00










  • yep, no changes... also, I edited my question
    – Doc
    Nov 6 at 14:07















up vote
0
down vote

favorite












I'm trying to import some services using barrels and tsconfigs paths options but I can't get angular and vscode to get along.



If it works for one it doesn't for the other and viceversa...



My situation seems to be pretty simple:




  • in src/app/services I have a service which is exported in a index.ts

  • my src/tsconfig.app.json is just this:




{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"types": ,
"baseUrl": ".",
"paths": {
"services": ["app/services"]
}
},
"exclude": [
"test.ts",
"**/*.spec.ts"
],
}


and my angular app compiles with no issues, but vscode keep giving me errors every time I try to import my service from 'services' giving me [ts] Cannot find module 'services'.



why?



I'm using typescript 3.1.6 and in vscode settings I have "typescript.tsdk": "C:/Users/myuser/AppData/Roaming/npm/node_modules/typescript/lib" (I also tried to leave the default setting, no changes)





edit:



if I specify paths in ./tsconfig.json starting from src, vscode is happy but angular is not.



if I specify paths in both tsconfig.json and src/tsconfig.app.json, both vscode and angular are happy, but it seems a too stupid workaround to me...










share|improve this question
























  • And did you try setting the TSDK to your project instead of the NPM one ?
    – trichetriche
    Nov 6 at 14:00










  • yep, no changes... also, I edited my question
    – Doc
    Nov 6 at 14:07













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm trying to import some services using barrels and tsconfigs paths options but I can't get angular and vscode to get along.



If it works for one it doesn't for the other and viceversa...



My situation seems to be pretty simple:




  • in src/app/services I have a service which is exported in a index.ts

  • my src/tsconfig.app.json is just this:




{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"types": ,
"baseUrl": ".",
"paths": {
"services": ["app/services"]
}
},
"exclude": [
"test.ts",
"**/*.spec.ts"
],
}


and my angular app compiles with no issues, but vscode keep giving me errors every time I try to import my service from 'services' giving me [ts] Cannot find module 'services'.



why?



I'm using typescript 3.1.6 and in vscode settings I have "typescript.tsdk": "C:/Users/myuser/AppData/Roaming/npm/node_modules/typescript/lib" (I also tried to leave the default setting, no changes)





edit:



if I specify paths in ./tsconfig.json starting from src, vscode is happy but angular is not.



if I specify paths in both tsconfig.json and src/tsconfig.app.json, both vscode and angular are happy, but it seems a too stupid workaround to me...










share|improve this question















I'm trying to import some services using barrels and tsconfigs paths options but I can't get angular and vscode to get along.



If it works for one it doesn't for the other and viceversa...



My situation seems to be pretty simple:




  • in src/app/services I have a service which is exported in a index.ts

  • my src/tsconfig.app.json is just this:




{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"types": ,
"baseUrl": ".",
"paths": {
"services": ["app/services"]
}
},
"exclude": [
"test.ts",
"**/*.spec.ts"
],
}


and my angular app compiles with no issues, but vscode keep giving me errors every time I try to import my service from 'services' giving me [ts] Cannot find module 'services'.



why?



I'm using typescript 3.1.6 and in vscode settings I have "typescript.tsdk": "C:/Users/myuser/AppData/Roaming/npm/node_modules/typescript/lib" (I also tried to leave the default setting, no changes)





edit:



if I specify paths in ./tsconfig.json starting from src, vscode is happy but angular is not.



if I specify paths in both tsconfig.json and src/tsconfig.app.json, both vscode and angular are happy, but it seems a too stupid workaround to me...







angular typescript visual-studio-code vscode-settings tsconfig






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 6 at 14:04

























asked Nov 6 at 13:52









Doc

1,45642653




1,45642653












  • And did you try setting the TSDK to your project instead of the NPM one ?
    – trichetriche
    Nov 6 at 14:00










  • yep, no changes... also, I edited my question
    – Doc
    Nov 6 at 14:07


















  • And did you try setting the TSDK to your project instead of the NPM one ?
    – trichetriche
    Nov 6 at 14:00










  • yep, no changes... also, I edited my question
    – Doc
    Nov 6 at 14:07
















And did you try setting the TSDK to your project instead of the NPM one ?
– trichetriche
Nov 6 at 14:00




And did you try setting the TSDK to your project instead of the NPM one ?
– trichetriche
Nov 6 at 14:00












yep, no changes... also, I edited my question
– Doc
Nov 6 at 14:07




yep, no changes... also, I edited my question
– Doc
Nov 6 at 14:07












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










I figured it out, even if I'm keep thinking that is all absurd...



VsCode automatically look for a tsconfig.json file and it doesn't care about tsconfig.app.json, so paths needs to be specified in tsconfig.json.



At the same time, the angular-cli scaffolding specify a baseUrl parameter in tsconfig.app.json which overrides the upper one.



The solution is to delete baseUrl parameter in the tsconfig.app.json or edit its value to "../"



(As a personal remark, given that vscode is largely used to build angular solutions, I think that there's something that should be revisited in the angular-cli scaffolding or in how vscode looks for tsconfig files)






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53173306%2fvisual-studio-code-cant-resolve-angulars-tsconfig-paths%23new-answer', 'question_page');
    }
    );

    Post as a guest
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    I figured it out, even if I'm keep thinking that is all absurd...



    VsCode automatically look for a tsconfig.json file and it doesn't care about tsconfig.app.json, so paths needs to be specified in tsconfig.json.



    At the same time, the angular-cli scaffolding specify a baseUrl parameter in tsconfig.app.json which overrides the upper one.



    The solution is to delete baseUrl parameter in the tsconfig.app.json or edit its value to "../"



    (As a personal remark, given that vscode is largely used to build angular solutions, I think that there's something that should be revisited in the angular-cli scaffolding or in how vscode looks for tsconfig files)






    share|improve this answer



























      up vote
      0
      down vote



      accepted










      I figured it out, even if I'm keep thinking that is all absurd...



      VsCode automatically look for a tsconfig.json file and it doesn't care about tsconfig.app.json, so paths needs to be specified in tsconfig.json.



      At the same time, the angular-cli scaffolding specify a baseUrl parameter in tsconfig.app.json which overrides the upper one.



      The solution is to delete baseUrl parameter in the tsconfig.app.json or edit its value to "../"



      (As a personal remark, given that vscode is largely used to build angular solutions, I think that there's something that should be revisited in the angular-cli scaffolding or in how vscode looks for tsconfig files)






      share|improve this answer

























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        I figured it out, even if I'm keep thinking that is all absurd...



        VsCode automatically look for a tsconfig.json file and it doesn't care about tsconfig.app.json, so paths needs to be specified in tsconfig.json.



        At the same time, the angular-cli scaffolding specify a baseUrl parameter in tsconfig.app.json which overrides the upper one.



        The solution is to delete baseUrl parameter in the tsconfig.app.json or edit its value to "../"



        (As a personal remark, given that vscode is largely used to build angular solutions, I think that there's something that should be revisited in the angular-cli scaffolding or in how vscode looks for tsconfig files)






        share|improve this answer














        I figured it out, even if I'm keep thinking that is all absurd...



        VsCode automatically look for a tsconfig.json file and it doesn't care about tsconfig.app.json, so paths needs to be specified in tsconfig.json.



        At the same time, the angular-cli scaffolding specify a baseUrl parameter in tsconfig.app.json which overrides the upper one.



        The solution is to delete baseUrl parameter in the tsconfig.app.json or edit its value to "../"



        (As a personal remark, given that vscode is largely used to build angular solutions, I think that there's something that should be revisited in the angular-cli scaffolding or in how vscode looks for tsconfig files)







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 17 hours ago

























        answered Nov 6 at 14:23









        Doc

        1,45642653




        1,45642653






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53173306%2fvisual-studio-code-cant-resolve-angulars-tsconfig-paths%23new-answer', 'question_page');
            }
            );

            Post as a guest




















































































            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Lugert, Oklahoma