Close Menu
geekfence.comgeekfence.com
    What's Hot

    Wilkie refers gambling concerns to anti-corruption commission

    August 13, 2026

    Lumen ready for AI traffic rush – with programmable fabric and “more fiber than anyone”

    August 13, 2026

    With a feel for physics, AI models simulate a wider range of real-world scenarios | MIT News

    August 13, 2026
    Facebook X (Twitter) Instagram
    • About Us
    • Contact Us
    Facebook Instagram
    geekfence.comgeekfence.com
    • Home
    • UK Tech News
    • AI
    • Big Data
    • Cyber Security
      • Cloud Computing
      • iOS Development
    • IoT
    • Mobile
    • Software
      • Software Development
      • Software Engineering
    • Technology
      • Green Technology
      • Nanotechnology
    • Telecom
    geekfence.comgeekfence.com
    Home»Software Engineering»Why and How to Use Absolute Imports in React
    Software Engineering

    Why and How to Use Absolute Imports in React

    AdminBy AdminJuly 12, 2026No Comments3 Mins Read5 Views
    Facebook Twitter Pinterest LinkedIn Telegram Tumblr Email
    Why and How to Use Absolute Imports in React
    Share
    Facebook Twitter LinkedIn Pinterest Email


    Absolute Imports

    By using absolute imports, you can alias some folders to a name like below:

    import {MyComponent} from ‘components/MyComponent’;

    Absolute imports have some advantages.

    • There is no ../../../../hell. Therefore easier to type out the imports.
    • Easily copy-paste the code with imports into another file in the project and not have to tinker with import paths.
    • It is short and sweet

    The below example is a file with Relative imports.

    Make the imports in the above file prettier.

    Therefore, how can you use absolute imports with ReactJs?

    Using TypeScript

    If you need to set up absolute imports in your Typescript application add/update your tsconfig.json file in the root directory of the project. Then you need to update the compiler option baseUrl in the file.

    Using JavaScript

    Setting up absolute imports to Typescript and setting up absolute imports to JavaScript is pretty much the same process. Create the jsconfig.json file in the root directory of the project. Then you need to update the following snippet.

    Now you can import your components like this.

    import {MyComponent} from ‘components/MyComponent’;

    You can also use the compiler option paths as well. Perhaps you want to alias your component folder. For that, you need to set up your tsconfig.json, or jsconfig.json as shown in below:

    {
    "compilerOptions": {
    "baseUrl": "./",
    "paths": {
    "@component/*": ["src/components/*"],
    }
    }
    }

    Now you can import the components from your component folder like this:

    import {MyComponent} from ‘@component/MyComponent’;

    is that enough?

    Get Sabesan Sathananthan’s stories in your inbox

    Join Medium for free to get updates from this writer.

    Well, no… You need to make your IDE smart to understand absolute imports in your files. Here I am going to mention the progress for the top 2 IDEs. Those are VS Code and WebStrom.

    For VS Code

    VS Code is smart enough to understand the tsconfig.json, or jsconfig.json file. Intellisense and jump-to-source are just working fine with absolute imports.

    Therefore, you can follow the above process.

    For WebStrom / IntelliJ Idea

    Select the src folder in the project window and right-click on it. Select the option Mark Directory as and then select the Resources Root option.

    Press enter or click to view image in full size

    Now go to Settings -> Editor –> Code Style -> JavaScript and select the Imports tab. Then check the Use paths relative to the project, resource or sources roots.

    Press enter or click to view image in full size

    Now WebStrom knows where the absolute imports are pointing. There won’t no warnings and autocomplete/ jump-to-source will work. This means the auto-import mechanism uses absolute imports.

    If you are a strict developer like me, use something like Airbnb’s ESLint config.

    With ESLint

    Create React App also has an ESLint setup but it has a minimal set of rules. eslint-plugin-import is used by Airbnb and this plugin checks undefined imports. When you are going to use Airbnb’s ESLint config it will give you the error shown below:

    You can fix the error by add settings prop in your ESLint config. That setting prop point that your imports might be relative to src folder. Therefore, you need to add update your ESLint config in .eslintrc file like this:

    You don’t need to install any NPM modules to avoid the ESLint error, add the settings prop is enough.

    By Convention

    Absolute imports have been possible for a long time with Webpack. When you are naming your aliased folder, you need to use PascalCase/CamelCase because it is the convention follow in the Webpack.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

    Related Posts

    SED News: The Kimi Moment, Runaway AI, and Tokenmaxxing

    August 11, 2026

    Jason Gorman on The Effective Use of AI For Software Development – Software Engineering Radio

    August 7, 2026

    The Terminal as an Agentic Interface

    August 6, 2026

    Sonali Varde on AI and the Engineering Manager Role – Software Engineering Radio

    August 2, 2026

    Docker and Sandboxing AI Agents

    August 1, 2026

    Tabs Versus Spaces: Defining a Coding Standard

    July 30, 2026
    Top Posts

    Understanding U-Net Architecture in Deep Learning

    November 25, 202576 Views

    The Next Paradigm in Efficient Inference Scaling – The Berkeley Artificial Intelligence Research Blog

    May 16, 202642 Views

    Is it too late to start learning AI and machine learning in my 30s or 40s?

    April 9, 202637 Views
    Don't Miss

    Wilkie refers gambling concerns to anti-corruption commission

    August 13, 2026

    Independent MP Andrew Wilkie has taken the fight over gambling reform to the National Anti-Corruption…

    Lumen ready for AI traffic rush – with programmable fabric and “more fiber than anyone”

    August 13, 2026

    With a feel for physics, AI models simulate a wider range of real-world scenarios | MIT News

    August 13, 2026

    Monitoring beyond SNMP: Turning your network into a sensor

    August 13, 2026
    Stay In Touch
    • Facebook
    • Instagram
    About Us

    At GeekFence, we are a team of tech-enthusiasts, industry watchers and content creators who believe that technology isn’t just about gadgets—it’s about how innovation transforms our lives, work and society. We’ve come together to build a place where readers, thinkers and industry insiders can converge to explore what’s next in tech.

    Our Picks

    Wilkie refers gambling concerns to anti-corruption commission

    August 13, 2026

    Lumen ready for AI traffic rush – with programmable fabric and “more fiber than anyone”

    August 13, 2026

    Subscribe to Updates

    Please enable JavaScript in your browser to complete this form.
    Loading
    • About Us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • Terms and Conditions
    © 2026 Geekfence.All Rigt Reserved.

    Type above and press Enter to search. Press Esc to cancel.