Skip to content

Commit f1c04b6

Browse files
committed
Validate when creating a page that the page component exists
1 parent 3739df7 commit f1c04b6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/gatsby/src/redux/actions.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,25 @@ actions.createPage = (page: PageInput, plugin?: Plugin, traceId?: string) => {
122122
noPageOrComponent = true
123123
}
124124

125+
if (!fs.existsSync(page.component)) {
126+
const message = `${name} created a page with a component that doesn't exist`
127+
// Don't log out when testing
128+
if (process.env.NODE_ENV !== `test`) {
129+
console.log(``)
130+
console.log(chalk.bold.red(message))
131+
console.log(``)
132+
console.log(page)
133+
} else {
134+
return message
135+
}
136+
noPageOrComponent = true
137+
}
138+
125139
if (!page.component || !path.isAbsolute(page.component)) {
126140
const message = `${name} must set the absolute path to the page component when create creating a page`
127141
// Don't log out when testing
128142
if (process.env.NODE_ENV !== `test`) {
143+
console.log(``)
129144
console.log(chalk.bold.red(message))
130145
console.log(``)
131146
console.log(page)
@@ -140,6 +155,7 @@ actions.createPage = (page: PageInput, plugin?: Plugin, traceId?: string) => {
140155
console.log(
141156
`See the documentation for createPage https://www.gatsbyjs.org/docs/bound-action-creators/#createPage`
142157
)
158+
console.log(``)
143159
process.exit(1)
144160
}
145161

0 commit comments

Comments
 (0)