Gatsby: Is it possible to add a resolve path to webpack config?

Created on 30 Sep 2016  路  7Comments  路  Source: gatsbyjs/gatsby

I see how I can add plugins and loaders, but what about a root resolve path?
I always do something like this in my projects and it is very helpful.

resolve: {
    root: path.resolve(__dirname, './src'),
    extensions: ['', '.js', '.jsx', '.json'],
  },
Hacktoberfest documentation

Most helpful comment

as gatsby-node doesnt looks like to support es6/babel, we need to write this as ES5. Also, note the destructuring in modifyWebpackConfig arguments

exports.modifyWebpackConfig = function({config, env}) {
  config.merge({
    resolve: {
      root: path.resolve(__dirname, './src'),
      extensions: ['', '.js', '.jsx', '.json'],
    }
  });
  return config;
}

All 7 comments

In gatsby-node.js

export function modifyWebpackConfig(config, env) {
  config.merge({
    resolve: {
      root: path.resolve(__dirname, './src'),
      extensions: ['', '.js', '.jsx', '.json'],
    }
  });
  return config;
}

It'd be good to add this to the README for documentation.

as gatsby-node doesnt looks like to support es6/babel, we need to write this as ES5. Also, note the destructuring in modifyWebpackConfig arguments

exports.modifyWebpackConfig = function({config, env}) {
  config.merge({
    resolve: {
      root: path.resolve(__dirname, './src'),
      extensions: ['', '.js', '.jsx', '.json'],
    }
  });
  return config;
}

@KyleAMathews what about a FAQ section in the docs ? i could add a note there

@revolunet gatsby-node.js is run by Node.js so it supports the JS your version of Node supports. So use Node 8 if you want support for (most) ES6 features.

Updated: while was writing the comment, already solved my problem. Don't know, might be a problem with webpack resolver too.

I had the next error:

Uncaught Error: [React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.

The problem was that I moved Header out of layouts/index.js to layouts/Header/index.js. That leads to error which i described above.
import { FormattedMessage } from 'react-intl' can't be resolved.

My solution was to put header in src/component/Header/index.js instead.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KyleAMathews picture KyleAMathews  路  3Comments

mikestopcontinues picture mikestopcontinues  路  3Comments

brandonmp picture brandonmp  路  3Comments

3CordGuy picture 3CordGuy  路  3Comments

magicly picture magicly  路  3Comments