Enable absolute imports for Gatsby v2

1 min read

If you prefer absolute imports like with GatsbyJS v2 add the following snippet to your gatsby-node.js file.

const path = require('path');

exports.onCreateWebpackConfig = ({ stage, actions }) => {
    resolve: {
      modules: [path.resolve(__dirname, "src"), "node_modules"],

Then you con import like so:

import from 'components/MyComponent'

Rating: 5.0 - 3 Reviews
Is this post useful to you? Please give us a rating!


Want regular updates on Gatsby and its awesomeness? Subscribe here. No spam, promise. Full details on privacy.

We use MailChimp as our marketing automation platform. By clicking "Submit" to submit this form, you acknowledge that the information you provide will be transferred to MailChimp for processing in accordance with their Privacy Policy and Terms.


If you'd like to share this post, here are some handy links to make that easier.

Post last updated: October 14, 2018


Feedback? A point to make? Express yourself via the comment form below.

Don't forget to check the captcha. Otherwise we won't receive your comment.

Be the first to post a comment on this post