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

Heroku部署Discord.js应用时遭遇权限拒绝错误求助

Hey there, let's fix this Heroku deployment issue for your Discord.js bot! Looking at your error logs, there are two key issues causing the permission denied error with node-pre-gyp, and we can resolve them step by step:

Step 1: Remove node_modules from Git (critical fix)

The log explicitly calls out "node_modules checked into source control" — this is the primary culprit here. Heroku needs to install dependencies from scratch in its isolated environment, and your local node_modules folder contains system-specific files that trigger permission conflicts during the build. Here's what to do:

  • Delete your local node_modules folder and package-lock.json (or yarn.lock if you use Yarn)
  • Open your .gitignore file and ensure it includes this line: node_modules/ (add it if it's missing)
  • Commit these changes to Git:
    git add .gitignore
    git rm -r --cached node_modules
    git commit -m "Remove node_modules from Git and update .gitignore"
    
Step 2: Specify Node.js and npm versions in package.json

Your log shows "engines.node (package.json): unspecified" — using an unversioned Node environment can lead to compatibility problems with native packages like @discordjs/opus. Let's lock in a stable version:

  • Open your package.json file and add an engines section. For Discord.js v14+ (the recommended current version), use Node 16.9 or higher. Example:
    "engines": {
      "node": "18.x",
      "npm": "8.x"
    }
    
  • Commit this change to Git:
    git add package.json
    git commit -m "Specify Node.js and npm versions"
    
Step 3: Redeploy to Heroku

Push your updated code to Heroku to trigger a fresh build:

git push heroku main
Extra Troubleshooting Tip

If you still encounter issues after the above steps, clear Heroku's build cache to ensure a completely clean dependency install:

heroku repo:purge_cache -a your-app-name

Replace your-app-name with the exact name of your Heroku application.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 08:02:35