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?
Create React App does not currently support
baseUrl
. However there is a workaround...to setupbaseUrl
for both webpack and the IDE you have to do the following:.env
file with the following code:tsconfig.paths.json
file with the following code inside:tsconfig.json
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.
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:
tsconfig.json