Absolute imports and module path aliases are a game changer!

Absolute imports and module path aliases are a game changer!

Absolute imports are indeed a game-changer, atleast for me.

Absolute imports are indeed a game-changer, at least for me. At times when you have different directories or files to import from, you’d perhaps know the challenge of trying to remember every folder structure so you don’t mess up while importing content.

Remember when you had to spend some time figuring out if the file you have imported is even the right one? It can get unexciting if that happens quite often. Imagine getting caught up in trying to identify if you have the right dots to your import path. As you can see in the image below, the left side of the split-screen shows the clutter due to relative paths while absolute paths on the right are much more cleaner and readable.

Image for post

Relative Imports (Left) & Absolute Imports (Right)

To make imports more readable Next.js has introduced the concept of absolute imports and module path alias options from v9.4. This is all possible through a config file that is supported automatically from Next.js v9.4 onwards. The files are tsconfig.json for Typescript and jsconfig.json for Javascript.

Before and After Absolute Imports

Without absolute imports, we had to drill down the actual path of the import.

Image for post

With absolute imports, it’s clean and easy.

Image for post

clean-code javascript nextjs

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript. Bugs are born in many ways. Creating side effects is one of them. Some people say side effects are evil, some say they’re not.

Who Else Wants to Write Clean JavaScript Code?

Who Else Wants to Write Clean JavaScript Code? 7 Tips to Make Your Coworkers Fall in Love With Your Code.

7 Tips to Write Clean JavaScript Code

Who Else Wants to Write Clean JavaScript Code? In this Javascript tutorial, you'll see 7 Tips to Make Your Coworkers Fall in Love With Your Code.

19 Simple JavaScript Coding Standards to Keep Your Code Clean

JavaScript coding standards for improving the quality of your code.This is important due to JavaScript being a dynamic language so using == might give you unexpected results due to it allowing the type to be different.

Static Code Analysis: What It Is? How to Use It?

Static code analysis is a method of debugging by examining source code before a program is run. It's done by analyzing a set of code against a set (or multiple sets) of coding rules. Static code analysis and static analysis are often used interchangeably, along with source code analysis.