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

CentOS 7.9安装Discord.js报错求助:node-gyp构建失败

修复CentOS 7.9安装Discord.js时的node-gyp/node-pre-gyp编译错误

1. 安装编译依赖包

CentOS 7.9默认缺少编译Node.js原生模块的基础工具和@discordjs/opus依赖的opus库,执行以下命令安装:

yum install -y gcc-c++ make python3-devel libopus-devel

若安装过程中node-gyp提示要求Python 2环境,可替换为python2-devel,同时设置npm指定Python版本:

npm config set python /usr/bin/python2

2. 清理缓存后重新安装

删除本地已生成的依赖文件与锁文件,清除npm缓存后重新执行安装:

rm -rf node_modules package-lock.json
npm cache clean --force
npm install

3. 强制从源码编译@discordjs/opus

报错显示预编译的opus模块无法适配当前系统环境,可强制从源码编译该模块:

npm install @discordjs/opus --build-from-source

或者在安装Discord.js时直接指定编译参数:

npm install discord.js --build-from-source=@discordjs/opus

4. 匹配node-gyp的Python版本要求

node 16.x对应的node-gyp v9.1.0要求Python 3.6+或Python 2.7,若系统默认Python版本不满足,可安装python36并配置:

yum install -y centos-release-scl
yum install -y rh-python36
scl enable rh-python36 bash
npm config set python /usr/bin/python3.6

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 04:53:08