contentful-labs / starter-gatsby-blog

Gatsby starter for a Contentful project from the community.
https://contentful.github.io/starter-gatsby-blog/
MIT License
195 stars 199 forks source link

npm run dev - 'Something went wrong installing the "sharp" module' #250

Closed harry643 closed 6 months ago

harry643 commented 7 months ago

I get the error in the title when running npm run dev. Full output:

$ npm run dev

> contentful-starter-gatsby-blog@0.0.1 dev
> gatsby develop

 ERROR  UNKNOWN

(node:40066) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

 ERROR  UNKNOWN

(node:40094) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

success compile gatsby files - 1.028s
success load gatsby config - 0.018s

 ERROR  UNKNOWN

Error in "/home/harry/Documents/contentful-starter/node_modules/gatsby-transformer-sharp/gatsby-node":
Something went wrong installing the "sharp" module

Cannot find module '../build/Release/sharp-linux-x64.node'
Require stack:
- /home/harry/Documents/contentful-starter/node_modules/gatsby-plugin-sharp/node_modules/sharp/lib/sharp.js
- /home/harry/Documents/contentful-starter/node_modules/gatsby-plugin-sharp/node_modules/sharp/lib/constructor.js
- /home/harry/Documents/contentful-starter/node_modules/gatsby-plugin-sharp/node_modules/sharp/lib/index.js
- /home/harry/Documents/contentful-starter/node_modules/gatsby-plugin-sharp/safe-sharp.js
- /home/harry/Documents/contentful-starter/node_modules/gatsby-plugin-sharp/index.js
- /home/harry/Documents/contentful-starter/node_modules/gatsby-transformer-sharp/customize-schema.js
- /home/harry/Documents/contentful-starter/node_modules/gatsby-transformer-sharp/gatsby-node.js

Possible solutions:
- Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
- Install for the current linux-x64 runtime: "npm install --platform=linux --arch=x64 sharp"
- Consult the installation documentation: https://sharp.pixelplumbing.com/install

  Error: Something went wrong installing the "sharp" module
  Cannot find module '../build/Release/sharp-linux-x64.node'
  Require stack:
  - /home/harry/Documents/contentful-starter/node_modules/gatsby-plugin-sharp/node_modules/sharp/lib/sharp.js
  - /home/harry/Documents/contentful-starter/node_modules/gatsby-plugin-sharp/node_modules/sharp/lib/constructor.js
  - /home/harry/Documents/contentful-starter/node_modules/gatsby-plugin-sharp/node_modules/sharp/lib/index.js
  - /home/harry/Documents/contentful-starter/node_modules/gatsby-plugin-sharp/safe-sharp.js
  - /home/harry/Documents/contentful-starter/node_modules/gatsby-plugin-sharp/index.js
  - /home/harry/Documents/contentful-starter/node_modules/gatsby-transformer-sharp/customize-schema.js
  - /home/harry/Documents/contentful-starter/node_modules/gatsby-transformer-sharp/gatsby-node.js
  Possible solutions:
  - Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
  - Install for the current linux-x64 runtime: "npm install --platform=linux --arch=x64 sharp"
  - Consult the installation documentation: https://sharp.pixelplumbing.com/install

  - sharp.js:34 Object.<anonymous>
    [contentful-starter]/[gatsby-plugin-sharp]/[sharp]/lib/sharp.js:34:9

  - loader:1378 Module._compile
    node:internal/modules/cjs/loader:1378:14

  - loader:1437 Object.Module._extensions..js
    node:internal/modules/cjs/loader:1437:10

  - loader:1212 Module.load
    node:internal/modules/cjs/loader:1212:32

  - loader:1028 Function.Module._load
    node:internal/modules/cjs/loader:1028:12

  - loader:1237 Module.require
    node:internal/modules/cjs/loader:1237:19

  - helpers:176 require
    node:internal/modules/helpers:176:18

  - constructor.js:8 Object.<anonymous>
    [contentful-starter]/[gatsby-plugin-sharp]/[sharp]/lib/constructor.js:8:1

  - loader:1378 Module._compile
    node:internal/modules/cjs/loader:1378:14

  - loader:1437 Object.Module._extensions..js
    node:internal/modules/cjs/loader:1437:10

  - loader:1212 Module.load
    node:internal/modules/cjs/loader:1212:32

  - loader:1028 Function.Module._load
    node:internal/modules/cjs/loader:1028:12

  - loader:1237 Module.require
    node:internal/modules/cjs/loader:1237:19

  - helpers:176 require
    node:internal/modules/helpers:176:18

  - index.js:3 Object.<anonymous>
    [contentful-starter]/[gatsby-plugin-sharp]/[sharp]/lib/index.js:3:15

  - loader:1378 Module._compile
    node:internal/modules/cjs/loader:1378:14

not finished load plugins - 0.913s

Environment

node.js: 21.6.2 npm: 10.4.0 gatsby-cli: 5.13.2

harry643 commented 6 months ago

This seems to be due to the npm bug as mentioned in the warning banner in the sharp docs here: https://sharp.pixelplumbing.com/install#npm-v10

I fixed the error by deleting package-lock.json and node_modules directory, then running npm install to install the packages in package.json.