From 688bca4ac58656d876c8f95d16954ed6f2d8adcf Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Fri, 16 Feb 2018 22:12:35 -0800 Subject: [PATCH] Catch and exit if someone mistakenly puts their gatsby-config.js in the src directory fixes #2674 --- packages/gatsby/src/bootstrap/get-config-file.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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) } }