Skip to content

Commit 2104a9f

Browse files
sidharthachatterjeepieh
authored andcommitted
fix(gatsby-plugin-sharp): bail early if sharp isn't working (#10677)
We've seen several issues where builds break because `gatsby-plugin-sharp` fails for some reason. Typically because `sharp` didn't build correctly during install like in #10620 most likely due to an incorrect version of python From https://github.com/nodejs/node-gyp > python (v2.7 recommended, v3.x.x is not supported) This PR adds a try-catch around requiring `sharp` and bails early if it fails
1 parent dfe93ee commit 2104a9f

File tree

1 file changed

+19
-0
lines changed
  • packages/gatsby-plugin-sharp/src

1 file changed

+19
-0
lines changed

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

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
try {
2+
require(`sharp`)
3+
} catch (error) {
4+
// Bail early if sharp isn't available
5+
console.error(
6+
`
7+
The dependency "sharp" does not seem to have been built or installed correctly.
8+
9+
- Try to reinstall packages and look for errors during installation
10+
- Consult "sharp" installation page at http://sharp.pixelplumbing.com/en/stable/install/
11+
12+
If neither of the above work, please open an issue in https://github.com/gatsbyjs/gatsby/issues
13+
`
14+
)
15+
console.log()
16+
console.error(error)
17+
process.exit(1)
18+
}
19+
120
const sharp = require(`sharp`)
221
const crypto = require(`crypto`)
322
const imageSize = require(`probe-image-size`)

0 commit comments

Comments
 (0)