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

Heroku部署Discord机器人失败,遇node-pre-gyp权限拒绝错误求助

Fixing Heroku Deployment Failure for Your Discord Bot

Let's walk through resolving this deployment issue step by step—those two warnings from Heroku are exactly the starting points we need to address:

1. Remove node_modules from Git Version Control

Heroku is right to flag this: your local node_modules folder has system-specific files and permissions that don't translate to Heroku's environment, which is directly causing the node-pre-gyp: Permission denied error. Here's how to fix it:

  • First, make sure you have a .gitignore file in your project root. If you don't, create one and add this line:
    node_modules/
    
  • Next, remove the existing node_modules from Git's cached files (this won't delete the folder locally):
    git rm -r --cached node_modules
    
  • Commit this change to your repo:
    git commit -m "Remove node_modules from version control"
    

2. Specify Node & npm Versions in package.json

Heroku is falling back to a default Node 14.x version, but not locking in versions can lead to compatibility issues with packages like @discordjs/opus. Let's set versions that work for your bot:

  • Open your package.json file and add an engines section. Use the same Node version you're running locally (check with node -v in your terminal) or a stable LTS version. For example:
    "engines": {
      "node": "16.x",
      "npm": "8.x"
    }
    
  • Commit this update:
    git commit -m "Add Node and npm version specifications"
    

3. Redeploy to Heroku

Now push your updated code to Heroku:

git push heroku main

This should resolve the permission error and let Heroku properly install your dependencies in its own environment. The @discordjs/opus package will build correctly once Heroku handles the dependency installation from scratch, without relying on your local node_modules files.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 07:02:45