Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch and exit if someone mistakenly puts their gatsby-config.js in the src directory fixes #2674 #4101

Merged
merged 1 commit into from
Feb 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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