Skip to content

Commit

Permalink
panic on undefined error due to theme's import (#10740)
Browse files Browse the repository at this point in the history
## Description
If you mess up your component imports in a theme, resolveComponentPath will return undefined. Catching it and error before it errors on something else and returns a cryptic error.

## Related Issues
None
  • Loading branch information
jbolda authored and DSchau committed Jan 1, 2019
1 parent b03748d commit 0d31244
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require(`path`)
const report = require(`gatsby-cli/lib/reporter`)

module.exports = class GatsbyThemeComponentShadowingResolverPlugin {
cache = {}
Expand Down Expand Up @@ -34,13 +35,20 @@ module.exports = class GatsbyThemeComponentShadowingResolverPlugin {
path.join(theme, `src`, `components`)
)

const resolvedComponentPath = require.resolve(
this.resolveComponentPath({
theme,
component,
projectRoot: this.projectRoot,
})
)
const builtComponentPath = this.resolveComponentPath({
theme,
component,
projectRoot: this.projectRoot,
})
if (!builtComponentPath) {
// if you mess up your component imports in a theme, resolveComponentPath will return undefined
report.panic(
`We can't find the component located at ${
request.path
} and imported in ${request.context.issuer}`
)
}
const resolvedComponentPath = require.resolve(builtComponentPath)
// this callbackends the resolver fallthrough chain.
return callback(null, {
directory: request.directory,
Expand Down

0 comments on commit 0d31244

Please sign in to comment.