Skip to content

Commit 3487e48

Browse files
authored
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
1 parent d8937d0 commit 3487e48

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

examples/using-gatsby-image/gatsby-config.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = {
22
plugins: [
33
`gatsby-plugin-emotion`,
44
`gatsby-plugin-netlify`,
5+
`gatsby-plugin-sharp`,
56
`gatsby-transformer-sharp`,
67
{
78
resolve: `gatsby-source-filesystem`,

packages/gatsby-plugin-sharp/src/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const getImageSize = file => {
4040
// There is no guarantee that the module resolved is the module executing!
4141
// This can occur in mono repos depending on how dependencies have been hoisted.
4242
// The direct require has been left only to avoid breaking changes.
43-
let { boundActionCreators } = require(`gatsby/dist/redux/actions`)
43+
let boundActionCreators
4444
exports.setBoundActionCreators = actions => {
4545
boundActionCreators = actions
4646
}
@@ -107,6 +107,12 @@ function prepareQueue({ file, args }) {
107107
}
108108

109109
function createJob(job, { reporter }) {
110+
if (!boundActionCreators) {
111+
reporter.panic(
112+
`Gatsby-plugin-sharp wasn't setup correctly in gatsby-config.js. Make sure you add it to the plugins array.`
113+
)
114+
}
115+
110116
// Jobs can be duplicates and usually are long running tasks.
111117
// Because of that we shouldn't use async/await and instead opt to use
112118
// .then() /.catch() handlers, because this allows V8 to release

0 commit comments

Comments
 (0)