From 3487e484eff230bdccd9485e78f56f763276691f Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Sat, 1 Feb 2020 16:23:09 +0100 Subject: [PATCH] fix(gatsby-plugin-sharp): throw error when not added to gatsby-config (#21045) * fix(gatsby-plugin-sharp): throw error when not configured correctly * Update index.js --- examples/using-gatsby-image/gatsby-config.js | 1 + packages/gatsby-plugin-sharp/src/index.js | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/using-gatsby-image/gatsby-config.js b/examples/using-gatsby-image/gatsby-config.js index 3324d3e993035..678ad3b431e83 100644 --- a/examples/using-gatsby-image/gatsby-config.js +++ b/examples/using-gatsby-image/gatsby-config.js @@ -2,6 +2,7 @@ module.exports = { plugins: [ `gatsby-plugin-emotion`, `gatsby-plugin-netlify`, + `gatsby-plugin-sharp`, `gatsby-transformer-sharp`, { resolve: `gatsby-source-filesystem`, diff --git a/packages/gatsby-plugin-sharp/src/index.js b/packages/gatsby-plugin-sharp/src/index.js index 2ae2ab9aa04dd..6f0209f86f281 100644 --- a/packages/gatsby-plugin-sharp/src/index.js +++ b/packages/gatsby-plugin-sharp/src/index.js @@ -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 } @@ -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