Absolute imports in React projects
Use imports relative to src in Create React App or configure an @ alias in Next.js.
Relative imports get harder to read as a React project grows. A path like ../../components/button also changes if you move the file that imports it.
Create React App
Add this to jsconfig.json at the project root, or merge the compiler option into tsconfig.json for TypeScript.
{
"compilerOptions": {
"baseUrl": "src"
},
"include": ["src"]
}In Create React App, you can now import src/components/button.js as import Button from 'components/button'.
February 2025 update. React deprecated Create React App for new apps. This setup still applies to existing CRA projects.
Next.js
Next.js supports path aliases in the same config files. If your code lives under src/, merge in these options.
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*"]
}
}
}Now the import reads import Button from '@/components/button'. March 2026 update. TypeScript 6 deprecated baseUrl. The Next.js example uses paths relative to the config file, which works without baseUrl.
Other React setups depend on the bundler. TypeScript uses paths to resolve imports during checking and leaves the import strings as written in its output.