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
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'),
},
},
})
}
Most helpful comment
I have solved the issue with the following entry to gatsby-node.js