You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Heroku部署执行yarn install报错:Cannot find module node-gyp 求助

Fixing Sharp Node-Gyp Build Error on Heroku (No Package Changes Made)

Hey there, let's work through this sharp build error you're hitting on Heroku—this is a really common snag with native dependencies like sharp, especially when you haven't touched your package setup at all. Here are the most effective fixes to try:

1. Match Your Local Node.js Version to Heroku's

Node-gyp is super sensitive to Node.js version mismatches. Make sure the version defined in your package.json (under the engines field) exactly matches what you're using locally.

  • Run node -v on your machine to get your local version.
  • Update your package.json to reflect that, for example:
    "engines": {
      "node": "10.15.0"
    }
    

Heroku uses this version to build your app, so aligning it eliminates a huge source of build failures.

2. Purge Heroku's Build Cache

Corrupted cached dependencies are often the culprit when builds break without code changes. Clear Heroku's cache to force a fresh install:

heroku builds:cache:purge

After running this, redeploy your app—this will make Heroku pull and build all dependencies from scratch instead of relying on old cached files.

3. Force Sharp to Use Prebuilt Binaries

Sharp offers precompiled binaries for most environments, but sometimes Heroku's build setup triggers a source build instead. Tell sharp to use prebuilt binaries with a config var:

heroku config:set SHARP_IGNORE_GLOBAL_LIBVIPS=1

This skips the local build step and uses the precompiled version that's compatible with Heroku's environment.

4. Upgrade Your Heroku Stack (If Needed)

In 2018, Heroku's older stacks like cedar-14 lacked some system libraries sharp needs to build. Upgrading to the heroku-16 stack (which was the stable version back then) will fix missing dependencies:

heroku stack:set heroku-16

Redeploy after changing the stack—this ensures your app has access to the right system-level tools for sharp to compile successfully.

If none of these fix the issue, run heroku logs --tail while deploying to get the full error details. Sometimes the log will mention missing libraries (like libvips) that the stack upgrade or cache purge should resolve.

内容的提问来源于stack exchange,提问作者TheNastyOne

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 03:40:10