Here's my setup:
// tsconfig.json
{
"extends": "./tsconfig.paths.json",
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}
Then, I created a tsconfig.paths.json:
// tsconfig.paths.json
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@components/*": ["components/*"]
}
}
}
Finally, my craco config:
// craco.config.js
module.exports = {
style: {
postcss: {
plugins: [
{
plugin: require('craco-alias'),
source: "tsconfig",
baseUrl: "./src",
tsConfigPath: "./tsconfig.paths.json",
debug: true,
},
require('tailwindcss'),
require('autoprefixer'),
],
},
},
}
And yet:
-> yarn build
yarn run v1.22.10
$ craco build
The following changes are being made to your tsconfig.json file:
- compilerOptions.paths must not be set (aliased imports are not supported)
Creating an optimized production build...
Failed to compile.
./src/index.tsx
Cannot find module: '@components/App'. Make sure this package is installed.
You can install this package by running: yarn add @components/App.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Why?
Here's my setup:
Then, I created a
tsconfig.paths.json:Finally, my
cracoconfig:And yet:
Why?