In my case ,i solved this issue using craco and craco-alias
-
Install craco and craco-alias
:npm install @craco/craco --save && npm i -D craco-alias -
Create
tsconfig.paths.jsonin root directory{ "compilerOptions": { "baseUrl": "./src", "paths": { "@components/*" : ["./components/*"] } } } -
Extend
tsconfig.paths.jsonintsconfig.json{ "extends": "./tsconfig.paths.json", //default configs... } -
Create
craco.config.jsin root direcoryconst 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" } } ] }; -
in
package.jsonswap"start": "react-scripts start"with"start": "craco start"