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;

  },

}

Categories:

Recent Projects

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

Let’s Build Something Great Together

Let’s discuss your project and see how Ruby on Rails can be your competitive advantage.

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