Skip to content

Commit

Permalink
fix(gatsby-plugin-sharp): throw error when not added to gatsby-config (
Browse files Browse the repository at this point in the history
…#21045)

* fix(gatsby-plugin-sharp): throw error when not configured correctly

* Update index.js
  • Loading branch information
wardpeet authored Feb 1, 2020
1 parent d8937d0 commit 3487e48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/using-gatsby-image/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
plugins: [
`gatsby-plugin-emotion`,
`gatsby-plugin-netlify`,
`gatsby-plugin-sharp`,
`gatsby-transformer-sharp`,
{
resolve: `gatsby-source-filesystem`,
Expand Down
8 changes: 7 additions & 1 deletion packages/gatsby-plugin-sharp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getImageSize = file => {
// There is no guarantee that the module resolved is the module executing!
// This can occur in mono repos depending on how dependencies have been hoisted.
// The direct require has been left only to avoid breaking changes.
let { boundActionCreators } = require(`gatsby/dist/redux/actions`)
let boundActionCreators
exports.setBoundActionCreators = actions => {
boundActionCreators = actions
}
Expand Down Expand Up @@ -107,6 +107,12 @@ function prepareQueue({ file, args }) {
}

function createJob(job, { reporter }) {
if (!boundActionCreators) {
reporter.panic(
`Gatsby-plugin-sharp wasn't setup correctly in gatsby-config.js. Make sure you add it to the plugins array.`
)
}

// Jobs can be duplicates and usually are long running tasks.
// Because of that we shouldn't use async/await and instead opt to use
// .then() /.catch() handlers, because this allows V8 to release
Expand Down

0 comments on commit 3487e48

Please sign in to comment.