gatsby: Cannot find module '../build/Release/sharp.node'
Description
Running gatsby develop
throws an error:
$ gatsby develop
success delete html and css files from previous builds — 0.050 s
success open and validate gatsby-config.js — 0.004 s
success copy gatsby files — 0.012 s
error UNHANDLED EXCEPTION
Error: Cannot find module '../build/Release/sharp.node'
- v8-compile-cache.js:159 require
[almost-hipster]/[v8-compile-cache]/v8-compile-cache.js:159:20
- constructor.js:10 Object.<anonymous>
[almost-hipster]/[sharp]/lib/constructor.js:10:15
- v8-compile-cache.js:178 Module._compile
[almost-hipster]/[v8-compile-cache]/v8-compile-cache.js:178:30
- v8-compile-cache.js:159 require
[almost-hipster]/[v8-compile-cache]/v8-compile-cache.js:159:20
- index.js:3 Object.<anonymous>
[almost-hipster]/[sharp]/lib/index.js:3:15
- v8-compile-cache.js:178 Module._compile
[almost-hipster]/[v8-compile-cache]/v8-compile-cache.js:178:30
- v8-compile-cache.js:159 require
[almost-hipster]/[v8-compile-cache]/v8-compile-cache.js:159:20
- index.js:562 Object.<anonymous>
[almost-hipster]/[gatsby-plugin-sharp]/index.js:562:13
- v8-compile-cache.js:178 Module._compile
[almost-hipster]/[v8-compile-cache]/v8-compile-cache.js:178:30
This started happening after I tried to install gatsby-plugin-google-analytics
and copy-pasted the necessary lines into the gatsby-config.js
file:
yarn add gatsby-plugin-google-analytics
See below for gatsby-config.js
.
Reverting to any previously working commit doesn’t fix the error, so it seems like some sort of caching issue.
The only workaround that worked for me is to deleting the entire project and re-clone it from git. Then everything works again:
cd ..
rm -rf project-name
git clone git@github.com:your-name/project-name.git
cd project-name
yarn
gatsby develop
It seems like any “weird” issue with gatsby can be fixed by committing your changes to git, nuking it all, and re-downloading.
Steps to reproduce
$ gatsby develop
Expected result
Gatsby development server should be running.
Actual result
Gatsby throws an error described above and exits.
Environment
- Gatsby version (
npm list gatsby
): 1.9.236 - gatsby-cli version (
gatsby --version
): 1.1.48 - Node.js version: 8.9.4
- Operating System: macOS 10.13.3
File contents (if changed):
gatsby-config.js
:
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-typography`,
options: {
pathToConfigModule: `src/utils/typography.js`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/src/images`,
name: 'images',
},
},
{
resolve: `gatsby-plugin-google-analytics`,
options: {
trackingId: "YOUR_GOOGLE_ANALYTICS_TRACKING_ID,
// Puts tracking script in the head instead of the body
head: false,
// Setting this parameter is optional
anonymize: true,
// Setting this parameter is also optional
respectDNT: true,
},
},
],
};
package.json
:
{
"name": "gatsby-starter-hello-world",
"description": "Gatsby hello world starter",
"license": "MIT",
"scripts": {
"develop": "gatsby develop",
"build": "gatsby build",
"serve": "gatsby serve"
},
"dependencies": {
"gatsby": "^1.9.236",
"gatsby-image": "^1.0.42",
"gatsby-link": "^1.6.39",
"gatsby-plugin-google-analytics": "^1.0.24",
"gatsby-plugin-sharp": "^1.6.41",
"gatsby-plugin-typography": "^1.7.18",
"gatsby-source-filesystem": "^1.5.27",
"gatsby-transformer-sharp": "^1.6.22",
"lodash": "^4.17.5",
"typography-theme-fairy-gates": "^0.15.11"
}
}
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 15
- Comments: 17 (1 by maintainers)
Commits related to this issue
- issue with Sharp package and npm tracking of issue can found here: https://github.com/gatsbyjs/gatsby/issues/4693 — committed to krtb/kurtbauer by krtb 5 years ago
- build(yarn): yikes... https://github.com/gatsbyjs/gatsby/issues/4693#issuecomment-554674217 — committed to virtuoushub/eleventy-classic-blog-starter by deleted user 4 years ago
Had the same error. Deleting
node_modules
,.cache
,public
and reinstalling all dependencies fixed it for me.here steps to resolve this issue:
npm cache clean --force
npm install npm@latest -g
gatsby develop
on your terminal/cmd. Good luck and happy coding again 👏Try this command it work for me
npm install sharp --unsafe-perm
I did set
npm config set ignore-scripts true
globally so the sharp library wasn’t compiled by it’s postinstall script.Putting it back to false (the default) and deleting node_modules/sharp and reinstalling fixed it.
@bartTC Thanks, this haunted me for a whole night, still, “npm config set ignore-scripts true” is very important, is there any workaround?
If anyone runs into this problem after updating Mac OS and the other solutions don’t work, the reason might be that your Xcode commandline tools need to be reinstalled. https://anansewaa.com/gyp-no-xcode-or-clt-version-detected-macos-catalina/
Hi all, I am running into a remarkably similar issue, but while trying to download
gatsby-plugin-feed
.This is my first time developing with Gatsby, so apologies if the issue is obvious and I just don’t know where to look.
result of
gatsby develop
package.json
gatsby-config.js
I’ve tried every combination of deleting
node_modules
,.cache
,public
I can find. I’ve tried yarn and npm. Seems to throw the same error every time.Any help is appreciated. Thanks so much.