diff --git a/packages/gatsby/src/bootstrap/get-config-file.js b/packages/gatsby/src/bootstrap/get-config-file.js index 26c67e89433e6..5334621b59114 100644 --- a/packages/gatsby/src/bootstrap/get-config-file.js +++ b/packages/gatsby/src/bootstrap/get-config-file.js @@ -4,6 +4,7 @@ const fs = require(`fs-extra`) const testRequireError = require(`../utils/test-require-error`) const report = require(`gatsby-cli/lib/reporter`) const chalk = require(`chalk`) +const path = require(`path`) function isNearMatch( fileName: string, @@ -18,7 +19,7 @@ module.exports = async function getConfigFile( configName: string, distance: number = 3 ) { - const configPath = `${rootDir}/${configName}` + const configPath = path.join(rootDir, configName) let configModule try { configModule = require(configPath) @@ -41,6 +42,13 @@ module.exports = async function getConfigFile( ) console.log(``) process.exit(1) + } else if (fs.existsSync(path.join(rootDir, `src`, configName))) { + console.log(``) + report.error( + `Your gatsby-config.js file is in the wrong place. You've placed in the src/ directory. It must instead be at the root of your site next to your package.json file.` + ) + console.log(``) + process.exit(1) } }