CentOS 系统给nodejs 项目安装依赖报错 make: g++: No such file or directory

我在给nodejs 项目安装依赖包的时候,报了如下错误

error /var/www/bsrm-api/node_modules/sleep: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments:
Directory: /var/www/bsrm-api/node_modules/sleep
Output:
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | x64
gyp info find Python using Python version 3.9.9 found at "/usr/bin/python3"
gyp info spawn /usr/bin/python3
gyp info spawn args [
gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/var/www/bsrm-api/node_modules/sleep/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/root/.cache/node-gyp/18.9.1/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/root/.cache/node-gyp/18.9.1',
gyp info spawn args   '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/root/.cache/node-gyp/18.9.1/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/var/www/bsrm-api/node_modules/sleep',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/var/www/bsrm-api/node_modules/sleep/build'
  CXX(target) Release/obj.target/node_sleep/module_init.o
make: g++: No such file or directory
make: *** [node_sleep.target.mk:116: Release/obj.target/node_sleep/module_init.o] Error 127
make: Leaving directory '/var/www/bsrm-api/node_modules/sleep/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:201:23)
gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! System Linux 5.10.0-60.70.0.94.oe2203.bclinux.x86_64
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /var/www/bsrm-api/node_modules/sleep
gyp ERR! node -v v18.9.1

有一个这个错误:
make: g++: No such file or directory

解决方案:

# CentOS 系统
sudo yum update
sudo yum install gcc-c++

# Ubuntu 系统
sudo apt-get update
sudo apt-get install g++

然后再去安装依赖就可以了。

你可能感兴趣的:(nodejs,centos,linux,运维)