Non-tech founder’s guide to choosing the right software development partner Download Ebook
Home>Blog>Absolute imports in next.js

Absolute imports in Next.js

When I was working on my first project with Next.js I spent a lot of time to find how to use absolute imports. The solution turned out to be quite simple. You need to indicate this resolve option in your next.config.js file:


module.exports = {

  webpack(config) {

    config.resolve.modules.push(__dirname)

    return config;

  },

}

Or if you want to add absolute path only for one directory you can use alias:


module.exports = {

  webpack(config) {

    config.resolve.alias['components'] = path.join(__dirname, 'components');

    return config;

  },

}

Discover More Reads

Recent Projects

We take pride in creating applications that drive growth and evolution, from niche startups to international companies.

Do you have a tech idea?

Let’s talk!

By submitting this form, you agree with JetRockets’ Privacy Policy

If you prefer email, write to us at hello@jetrockets.com