create-react-app Typescript 3.5, Path Alias

In my case ,i solved this issue using craco and craco-alias

  1. Install craco and craco-alias
    : npm install @craco/craco --save && npm i -D craco-alias

  2. Create tsconfig.paths.json in root directory

    {
        "compilerOptions": {
            "baseUrl": "./src",
            "paths": {
               "@components/*" : ["./components/*"]
             }
        }
    }
    
  3. Extend tsconfig.paths.json in tsconfig.json

    {
        "extends": "./tsconfig.paths.json",
        //default configs...
    } 
    
  4. Create craco.config.js in root direcory

      const CracoAlias = require("craco-alias");
    
      module.exports = {
         plugins: [
           {
              plugin: CracoAlias,
              options: {
                 source: "tsconfig",
                 // baseUrl SHOULD be specified
                 // plugin does not take it from tsconfig
                 baseUrl: "./src",
                 /* tsConfigPath should point to the file where "baseUrl" and "paths" 
                 are specified*/
                 tsConfigPath: "./tsconfig.paths.json"
              }
           }
        ]
      };
    
  5. in package.json swap "start": "react-scripts start" with "start": "craco start"

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)