Skip to content

Commit

Permalink
Catch and exit if someone mistakenly puts their gatsby-config.js in t…
Browse files Browse the repository at this point in the history
…he src directory fixes #2674
  • Loading branch information
KyleAMathews committed Feb 17, 2018
1 parent 5743934 commit 688bca4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/gatsby/src/bootstrap/get-config-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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)
}
}

Expand Down

0 comments on commit 688bca4

Please sign in to comment.