Skip to content

Commit 408156c

Browse files
authored
Catch and exit if someone mistakenly puts their gatsby-config.js in the src directory fixes #2674 (#4101)
1 parent 77794d2 commit 408156c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/gatsby/src/bootstrap/get-config-file.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const fs = require(`fs-extra`)
44
const testRequireError = require(`../utils/test-require-error`)
55
const report = require(`gatsby-cli/lib/reporter`)
66
const chalk = require(`chalk`)
7+
const path = require(`path`)
78

89
function isNearMatch(
910
fileName: string,
@@ -18,7 +19,7 @@ module.exports = async function getConfigFile(
1819
configName: string,
1920
distance: number = 3
2021
) {
21-
const configPath = `${rootDir}/${configName}`
22+
const configPath = path.join(rootDir, configName)
2223
let configModule
2324
try {
2425
configModule = require(configPath)
@@ -41,6 +42,13 @@ module.exports = async function getConfigFile(
4142
)
4243
console.log(``)
4344
process.exit(1)
45+
} else if (fs.existsSync(path.join(rootDir, `src`, configName))) {
46+
console.log(``)
47+
report.error(
48+
`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.`
49+
)
50+
console.log(``)
51+
process.exit(1)
4452
}
4553
}
4654

0 commit comments

Comments
 (0)