How to configure react-script so that it doesn't override tsconfig.json on 'start'












8















I'm currently using create-react-app to bootstrap one of my projects. Basically, I'm trying to set up paths in tsconfig.json by adding these to the default tsconfig.json generated by create-react-app:



"baseUrl": "./src",
"paths": {
"interfaces/*": [
"common/interfaces/*",
],
"components/*": [
"common/components/*",
],
},


However, every time I run yarn start which basically runs react-scripts start, it deletes my changes and generates the default configurations again.



How can I tell create-react-app to use my custom configs?










share|improve this question























  • From the docs, > You are not required to make a tsconfig.json file, one will be made for you. You are allowed to edit the generated TypeScript configuration.

    – Boy With Silver Wings
    Dec 15 '18 at 16:36






  • 1





    Unfortunately, if you edit the file, it gets overwritten by yarn start, throwing away any changes.

    – Glenn
    Jan 2 at 21:38
















8















I'm currently using create-react-app to bootstrap one of my projects. Basically, I'm trying to set up paths in tsconfig.json by adding these to the default tsconfig.json generated by create-react-app:



"baseUrl": "./src",
"paths": {
"interfaces/*": [
"common/interfaces/*",
],
"components/*": [
"common/components/*",
],
},


However, every time I run yarn start which basically runs react-scripts start, it deletes my changes and generates the default configurations again.



How can I tell create-react-app to use my custom configs?










share|improve this question























  • From the docs, > You are not required to make a tsconfig.json file, one will be made for you. You are allowed to edit the generated TypeScript configuration.

    – Boy With Silver Wings
    Dec 15 '18 at 16:36






  • 1





    Unfortunately, if you edit the file, it gets overwritten by yarn start, throwing away any changes.

    – Glenn
    Jan 2 at 21:38














8












8








8


2






I'm currently using create-react-app to bootstrap one of my projects. Basically, I'm trying to set up paths in tsconfig.json by adding these to the default tsconfig.json generated by create-react-app:



"baseUrl": "./src",
"paths": {
"interfaces/*": [
"common/interfaces/*",
],
"components/*": [
"common/components/*",
],
},


However, every time I run yarn start which basically runs react-scripts start, it deletes my changes and generates the default configurations again.



How can I tell create-react-app to use my custom configs?










share|improve this question














I'm currently using create-react-app to bootstrap one of my projects. Basically, I'm trying to set up paths in tsconfig.json by adding these to the default tsconfig.json generated by create-react-app:



"baseUrl": "./src",
"paths": {
"interfaces/*": [
"common/interfaces/*",
],
"components/*": [
"common/components/*",
],
},


However, every time I run yarn start which basically runs react-scripts start, it deletes my changes and generates the default configurations again.



How can I tell create-react-app to use my custom configs?







reactjs typescript create-react-app react-scripts






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 15 '18 at 16:03









CodeInternCodeIntern

13017




13017













  • From the docs, > You are not required to make a tsconfig.json file, one will be made for you. You are allowed to edit the generated TypeScript configuration.

    – Boy With Silver Wings
    Dec 15 '18 at 16:36






  • 1





    Unfortunately, if you edit the file, it gets overwritten by yarn start, throwing away any changes.

    – Glenn
    Jan 2 at 21:38



















  • From the docs, > You are not required to make a tsconfig.json file, one will be made for you. You are allowed to edit the generated TypeScript configuration.

    – Boy With Silver Wings
    Dec 15 '18 at 16:36






  • 1





    Unfortunately, if you edit the file, it gets overwritten by yarn start, throwing away any changes.

    – Glenn
    Jan 2 at 21:38

















From the docs, > You are not required to make a tsconfig.json file, one will be made for you. You are allowed to edit the generated TypeScript configuration.

– Boy With Silver Wings
Dec 15 '18 at 16:36





From the docs, > You are not required to make a tsconfig.json file, one will be made for you. You are allowed to edit the generated TypeScript configuration.

– Boy With Silver Wings
Dec 15 '18 at 16:36




1




1





Unfortunately, if you edit the file, it gets overwritten by yarn start, throwing away any changes.

– Glenn
Jan 2 at 21:38





Unfortunately, if you edit the file, it gets overwritten by yarn start, throwing away any changes.

– Glenn
Jan 2 at 21:38












3 Answers
3






active

oldest

votes


















4














I was able to do this by using advice from this issue.



Put the configuration options react scripts likes to remove in a separate file (e.g. paths.json) and reference it from tsconfig.json via the extends directive.



paths.json:



{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"interfaces/*": [ "common/interfaces/*"],
"components/*": [ "common/components/*"],
}
}
}


tsconfig.json



{
"extends": "./paths.json"
...rest of tsconfig.json
}





share|improve this answer































    1














    Create React App does not currently support baseUrl. However there is a workaround...to setup baseUrl for both webpack and the IDE you have to do the following:




    1. Create a .env file with the following code:


    NODE_PATH=./



    1. Create a tsconfig.paths.json file with the following code inside:


    {
    "compilerOptions": {
    "baseUrl": "src",
    "paths": {
    "src/*": ["*"]
    }
    }
    }



    1. Add the following line to tsconfig.json


    {
    "extends": "./tsconfig.paths.json",
    ...
    }





    share|improve this answer































      0














      You can't and I am unsure when you will be able to. I have been trying to use baseUrl and paths so I can avoid relative imports but as you can see they are intentionally removing certain values. The "(yet)" is encouraging but (sigh) who knows when they will officially be supporting it. I recommend subscribing to this github issue to be alerted if/when this changes.



      The following changes are being made to your tsconfig.json file:
      - compilerOptions.baseUrl must not be set (absolute imports are not supported (yet))
      - compilerOptions.paths must not be set (aliased imports are not supported)





      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',
        autoActivateHeartbeat: false,
        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%2f53794875%2fhow-to-configure-react-script-so-that-it-doesnt-override-tsconfig-json-on-star%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        4














        I was able to do this by using advice from this issue.



        Put the configuration options react scripts likes to remove in a separate file (e.g. paths.json) and reference it from tsconfig.json via the extends directive.



        paths.json:



        {
        "compilerOptions": {
        "baseUrl": "./src",
        "paths": {
        "interfaces/*": [ "common/interfaces/*"],
        "components/*": [ "common/components/*"],
        }
        }
        }


        tsconfig.json



        {
        "extends": "./paths.json"
        ...rest of tsconfig.json
        }





        share|improve this answer




























          4














          I was able to do this by using advice from this issue.



          Put the configuration options react scripts likes to remove in a separate file (e.g. paths.json) and reference it from tsconfig.json via the extends directive.



          paths.json:



          {
          "compilerOptions": {
          "baseUrl": "./src",
          "paths": {
          "interfaces/*": [ "common/interfaces/*"],
          "components/*": [ "common/components/*"],
          }
          }
          }


          tsconfig.json



          {
          "extends": "./paths.json"
          ...rest of tsconfig.json
          }





          share|improve this answer


























            4












            4








            4







            I was able to do this by using advice from this issue.



            Put the configuration options react scripts likes to remove in a separate file (e.g. paths.json) and reference it from tsconfig.json via the extends directive.



            paths.json:



            {
            "compilerOptions": {
            "baseUrl": "./src",
            "paths": {
            "interfaces/*": [ "common/interfaces/*"],
            "components/*": [ "common/components/*"],
            }
            }
            }


            tsconfig.json



            {
            "extends": "./paths.json"
            ...rest of tsconfig.json
            }





            share|improve this answer













            I was able to do this by using advice from this issue.



            Put the configuration options react scripts likes to remove in a separate file (e.g. paths.json) and reference it from tsconfig.json via the extends directive.



            paths.json:



            {
            "compilerOptions": {
            "baseUrl": "./src",
            "paths": {
            "interfaces/*": [ "common/interfaces/*"],
            "components/*": [ "common/components/*"],
            }
            }
            }


            tsconfig.json



            {
            "extends": "./paths.json"
            ...rest of tsconfig.json
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 2 at 22:02









            GlennGlenn

            754819




            754819

























                1














                Create React App does not currently support baseUrl. However there is a workaround...to setup baseUrl for both webpack and the IDE you have to do the following:




                1. Create a .env file with the following code:


                NODE_PATH=./



                1. Create a tsconfig.paths.json file with the following code inside:


                {
                "compilerOptions": {
                "baseUrl": "src",
                "paths": {
                "src/*": ["*"]
                }
                }
                }



                1. Add the following line to tsconfig.json


                {
                "extends": "./tsconfig.paths.json",
                ...
                }





                share|improve this answer




























                  1














                  Create React App does not currently support baseUrl. However there is a workaround...to setup baseUrl for both webpack and the IDE you have to do the following:




                  1. Create a .env file with the following code:


                  NODE_PATH=./



                  1. Create a tsconfig.paths.json file with the following code inside:


                  {
                  "compilerOptions": {
                  "baseUrl": "src",
                  "paths": {
                  "src/*": ["*"]
                  }
                  }
                  }



                  1. Add the following line to tsconfig.json


                  {
                  "extends": "./tsconfig.paths.json",
                  ...
                  }





                  share|improve this answer


























                    1












                    1








                    1







                    Create React App does not currently support baseUrl. However there is a workaround...to setup baseUrl for both webpack and the IDE you have to do the following:




                    1. Create a .env file with the following code:


                    NODE_PATH=./



                    1. Create a tsconfig.paths.json file with the following code inside:


                    {
                    "compilerOptions": {
                    "baseUrl": "src",
                    "paths": {
                    "src/*": ["*"]
                    }
                    }
                    }



                    1. Add the following line to tsconfig.json


                    {
                    "extends": "./tsconfig.paths.json",
                    ...
                    }





                    share|improve this answer













                    Create React App does not currently support baseUrl. However there is a workaround...to setup baseUrl for both webpack and the IDE you have to do the following:




                    1. Create a .env file with the following code:


                    NODE_PATH=./



                    1. Create a tsconfig.paths.json file with the following code inside:


                    {
                    "compilerOptions": {
                    "baseUrl": "src",
                    "paths": {
                    "src/*": ["*"]
                    }
                    }
                    }



                    1. Add the following line to tsconfig.json


                    {
                    "extends": "./tsconfig.paths.json",
                    ...
                    }






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Feb 11 at 15:02









                    MicrocipcipMicrocipcip

                    107216




                    107216























                        0














                        You can't and I am unsure when you will be able to. I have been trying to use baseUrl and paths so I can avoid relative imports but as you can see they are intentionally removing certain values. The "(yet)" is encouraging but (sigh) who knows when they will officially be supporting it. I recommend subscribing to this github issue to be alerted if/when this changes.



                        The following changes are being made to your tsconfig.json file:
                        - compilerOptions.baseUrl must not be set (absolute imports are not supported (yet))
                        - compilerOptions.paths must not be set (aliased imports are not supported)





                        share|improve this answer




























                          0














                          You can't and I am unsure when you will be able to. I have been trying to use baseUrl and paths so I can avoid relative imports but as you can see they are intentionally removing certain values. The "(yet)" is encouraging but (sigh) who knows when they will officially be supporting it. I recommend subscribing to this github issue to be alerted if/when this changes.



                          The following changes are being made to your tsconfig.json file:
                          - compilerOptions.baseUrl must not be set (absolute imports are not supported (yet))
                          - compilerOptions.paths must not be set (aliased imports are not supported)





                          share|improve this answer


























                            0












                            0








                            0







                            You can't and I am unsure when you will be able to. I have been trying to use baseUrl and paths so I can avoid relative imports but as you can see they are intentionally removing certain values. The "(yet)" is encouraging but (sigh) who knows when they will officially be supporting it. I recommend subscribing to this github issue to be alerted if/when this changes.



                            The following changes are being made to your tsconfig.json file:
                            - compilerOptions.baseUrl must not be set (absolute imports are not supported (yet))
                            - compilerOptions.paths must not be set (aliased imports are not supported)





                            share|improve this answer













                            You can't and I am unsure when you will be able to. I have been trying to use baseUrl and paths so I can avoid relative imports but as you can see they are intentionally removing certain values. The "(yet)" is encouraging but (sigh) who knows when they will officially be supporting it. I recommend subscribing to this github issue to be alerted if/when this changes.



                            The following changes are being made to your tsconfig.json file:
                            - compilerOptions.baseUrl must not be set (absolute imports are not supported (yet))
                            - compilerOptions.paths must not be set (aliased imports are not supported)






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 20 at 16:49









                            GentryRiggenGentryRiggen

                            35448




                            35448






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53794875%2fhow-to-configure-react-script-so-that-it-doesnt-override-tsconfig-json-on-star%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                                SQL update select statement

                                'app-layout' is not a known element: how to share Component with different Modules