I using the CRA + Typescript to set up my project. And I also config the paths
property in tsconfig
file to use the absolute path.
Seems everything works fine after my configuration. But when I start my App using npm run start
or run test. I find the paths
property will be automatically removed.
here is the tsconfig.json
file I configured.
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"baseUrl": ".",
"paths": {
"src/*": ["./src/*"]
}
},
"include": [
"src"
]
}
and I try to use like this way in the test file:
import i18n from 'src/i18n/mocks';
Is there something wrong with my configuration? can someone help me? thks.
The tsconfig. json file specifies the root files and the compiler options required to compile the project. JavaScript projects can use a jsconfig. json file instead, which acts almost the same but has some JavaScript-related compiler flags enabled by default.
The include and exclude properties take a list of glob-like file patterns. The supported glob wildcards are: * matches zero or more characters (excluding directory separators) ? matches any one character (excluding directory separators)
TypeScript's strict mode parameter can be configurated as several individual parameters for each specific case of type checking. So, basically, if you set the parameter strict to true in tsconfig. json it means that all these strict options are set to true.
with --lib you can specify a list of built-in API declaration groups that you can chose to include in your project. For instance, if you expect your runtime to have support for Map, Set and Promise (e.g. most evergreen browsers today), just include --lib es2015.
There's a workaround.
baseUrl
config and paths
in there. Those won't be overwritten by CRA.{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"src/*": ["./src/*"]
}
}
}
{
"extends": "./base-tsconfig.json"
}
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