Gatsby pnpm monorepo build failing with `Cannot find module '../build/Release/sharp-linux-x64.node'`

PLEASE help us help you by writing a good post!

  • We need to know your netlify site name. Example: gifted-antelope-58b104.netlify.app
  • DNS issues? Tell us the custom domain, tell us the error message! We can’t help if we don’t know your domain.
  • Build problems? Link or paste the FULL build log & build settings screenshot
  • Did you try Ask Netlify, our generative AI chatbot, before posting? It pulls info from Support Guides and recent solved forums posts.

The better the post - the faster the answer.

Site name: https://test-doppler.netlify.app/

Build Problem:
```
12:35:54 PM: > legacy-core@0.0.0 build /opt/build/repo/apps/legacy-core

12:35:54 PM: > npm-run-all -s ‘build:plugin’ ‘build:site’

12:35:55 PM: > legacy-core@0.0.0 build:plugin /opt/build/repo/apps/legacy-core

12:35:55 PM: > pnpm --filter @repo/gatsby-source-rehabpath run build

12:35:55 PM: > @repo/gatsby-source-rehabpath@0.1.0 build /opt/build/repo/packages/gatsby-source-rehabpath

12:35:55 PM: > tsc

12:35:57 PM: > legacy-core@0.0.0 build:site /opt/build/repo/apps/legacy-core

12:35:57 PM: > pnpm run build:plugin && gatsby build

12:35:58 PM: > legacy-core@0.0.0 build:plugin /opt/build/repo/apps/legacy-core

12:35:58 PM: > pnpm --filter @repo/gatsby-source-rehabpath run build

12:35:58 PM: > @repo/gatsby-source-rehabpath@0.1.0 build /opt/build/repo/packages/gatsby-source-rehabpath

12:35:58 PM: > tsc

12:36:03 PM: |======================|

12:36:03 PM: | GETTING ZYPPY TITLES |

12:36:03 PM: |======================|

12:36:03 PM: success compile gatsby files - 1.980s

12:36:03 PM: [dotenv@17.2.1] injecting env (0) from .env – tip: :gear: specify custom .env file path with { path: ‘/custom/path/.env’ }

12:36:03 PM: success load gatsby config - 0.037s

12:36:03 PM: info Using gatsby-adapter-netlify adapter

12:36:04 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)

12:36:04 PM: error Error in “/opt/build/repo/node_modules/.pnpm/gatsby-transformer-sharp@5.14.0_gatsby-plugin-sharp@5.14.0_gatsby@5.14.6_babel-eslint@1_66f09934705ffd736b9b6dafaedeb133/node_modules/gatsby-transformer-sharp/gatsby-node”:

12:36:04 PM: Something went wrong installing the “sharp” module

12:36:04 PM: Cannot find module ‘../build/Release/sharp-linux-x64.node’

12:36:04 PM: Require stack:

12:36:04 PM: - /opt/build/repo/node_modules/.pnpm/sharp@0.32.6/node_modules/sharp/lib/sharp.js

12:36:04 PM: - /opt/build/repo/node_modules/.pnpm/sharp@0.32.6/node_modules/sharp/lib/constructor.js

12:36:04 PM: - /opt/build/repo/node_modules/.pnpm/sharp@0.32.6/node_modules/sharp/lib/index.js

12:36:04 PM: - /opt/build/repo/node_modules/.pnpm/gatsby-plugin-sharp@5.14.0_gatsby@5.14.6_babel-eslint@10.1.0_eslint@8.57.1__encoding@0._02daaa07591772fdedd7505837604269/node_modules/gatsby-plugin-sharp/safe-sharp.js

12:36:04 PM: - /opt/build/repo/node_modules/.pnpm/gatsby-plugin-sharp@5.14.0_gatsby@5.14.6_babel-eslint@10.1.0_eslint@8.57.1__encoding@0._02daaa07591772fdedd7505837604269/node_modules/gatsby-plugin-sharp/index.js

12:36:04 PM: - /opt/build/repo/node_modules/.pnpm/gatsby-transformer-sharp@5.14.0_gatsby-plugin-sharp@5.14.0_gatsby@5.14.6_babel-eslint@1_66f09934705ffd736b9b6dafaedeb133/node_modules/gatsby-transformer-sharp/customize-schema.js

12:36:04 PM: - /opt/build/repo/node_modules/.pnpm/gatsby-transformer-sharp@5.14.0_gatsby-plugin-sharp@5.14.0_gatsby@5.14.6_babel-eslint@1_66f09934705ffd736b9b6dafaedeb133/node_modules/gatsby-transformer-sharp/gatsby-node.js

12:36:04 PM: Possible solutions:

12:36:04 PM: - Install with verbose logging and look for errors: “npm install --ignore-scripts=false --foreground-scripts --verbose sharp”

12:36:04 PM: - Install for the current linux-x64 runtime: “npm install --platform=linux --arch=x64 sharp”

12:36:04 PM: - Consult the installation documentation: https://sharp.pixelplumbing.com/install
```

Hi, @eduardo1. This looks like a sharp package install error. What is not clear is why dependencies are being installed during the build command step and not the dependency install step.

That said, you do appear to have resolved this in a later deploy. If you have the time and are willing to share your solution here, it’s quite likely that it would help out someone else in a similar situation in the future and I thank you in advance if you do so.

hi @luke , yes I was able to resolve this. In pnpm projects postinstall scripts in dependencies are disabled by default - however sharp needs its postinstall script to create a new file in node_modules for usage during the build step. You can turn off this pnpm functionality by adding sharp to onlyBuiltDependencies in either package.json or pnpm-workspace.yaml depending on your project setup.