Gatsby: jsconfig.json for Gatsby project is not respected

Created on 12 Jan 2019  路  1Comment  路  Source: gatsbyjs/gatsby

I am trying to set up a new project with gatsby and am trying to set compiler options like so:

{
  "compilerOptions": {
    "target": "es2017",
    "allowSyntheticDefaultImports": false,
    "baseUrl": "./",
    "paths": {
      "components/*": ["src/components/*"],
      "layouts/*": ["src/layouts/*"],
      "pages/*": ["src/pages/*"],
      "templates/*": ["src/templates/*"],
      "scss/*": ["src/scss/*"]
    }
  },
  "exclude": ["node_modules", "public", ".cache"]
}

My objective is being able to reference components and etc. with 'components/something' instead of '../components/something'

But when the compiler runs, it returns error

`ERROR in ./src/pages/index.js
Module not found: Error: Can't resolve 'components/Layout' in '/home/ec2-user/environment/chefs/src/pages'`

Any thoughts appreciated. Am on gatsby version 2.4.8

Most helpful comment

I have solved the issue with the following entry to gatsby-node.js

const path = require('path')
exports.onCreateWebpackConfig = ({ actions }) => {
  actions.setWebpackConfig({
    resolve: {
      alias: {
        components: path.resolve(__dirname, 'src/components'),
        templates: path.resolve(__dirname, 'src/templates'),
        scss: path.resolve(__dirname, 'src/scss'),
      },
    },
  })
}

>All comments

I have solved the issue with the following entry to gatsby-node.js

const path = require('path')
exports.onCreateWebpackConfig = ({ actions }) => {
  actions.setWebpackConfig({
    resolve: {
      alias: {
        components: path.resolve(__dirname, 'src/components'),
        templates: path.resolve(__dirname, 'src/templates'),
        scss: path.resolve(__dirname, 'src/scss'),
      },
    },
  })
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

timbrandin picture timbrandin  路  3Comments

hobochild picture hobochild  路  3Comments

Oppenheimer1 picture Oppenheimer1  路  3Comments

dustinhorton picture dustinhorton  路  3Comments

benstr picture benstr  路  3Comments