I created my React app with create-react-app app_name --typescript
. Since Typescript doesn't support NODE_PATH. I'm trying to use baseUrl in tsconfig.json
.
However, every time running yarn start
after putting "baseUrl": "src"
in "compilerOptions"
, the baseUrl gets gone. I feel like yarn start
resets tsconfig.json
.
How can I stop it to reset the file?
**tsconfig.json**
{
"compilerOptions": {
"target": "es6",
"allowJs": true,
"skipLibCheck": false,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve"
},
"include": ["src"]
}
There's a workaround.
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}
{
"extends": "./base-tsconfig.json"
}
More info here.
create-react-app currently removes the baseUrl
property, I don't think paths are currently supported by them unfortunately :(
Read more here https://github.com/facebook/create-react-app/issues/5585
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With