尝试通过 "npm install robotjs" 安装 RobotJS 时出现很多错误。知道我是否缺少一些依赖项或其他东西吗?



当我运行npm install robotjs时,我收到一条巨大的错误消息(粘贴在底部(

到目前为止,我已经尝试过:

  • 清除并重新安装节点
apt-get purge nodejs 
rm -r /etc/apt/sources.list.d/nodesource.list 
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
  • 将节点从18.x.0降级到16.16.0

sudo -E env "PATH=$PATH" n stable

  • 安装构建要素

apt-get install -y build-essential

  • 安装x11库

sudo apt-get install libx11-dev

如果有人能给我指明方向的话,我在这里不知所措。


系统信息

分发服务器ID:Ubuntu

描述:Ubuntu 22.04.1 LTS

发布时间:22.04

代号:jammy


npm ERR! code 1
npm ERR! path /home/alexei/coding-projects/repos/slither-bot/node_modules/robotjs
npm ERR! command failed
npm ERR! command sh -c prebuild-install || node-gyp rebuild
npm ERR! make: Entering directory '/home/alexei/coding-projects/repos/slither-bot/node_modules/robotjs/build'
npm ERR!   CXX(target) Release/obj.target/robotjs/src/robotjs.o
npm ERR!   CC(target) Release/obj.target/robotjs/src/deadbeef_rand.o
npm ERR!   CC(target) Release/obj.target/robotjs/src/mouse.o
npm ERR!   CC(target) Release/obj.target/robotjs/src/keypress.o
npm ERR!   CC(target) Release/obj.target/robotjs/src/keycode.o
npm ERR!   CC(target) Release/obj.target/robotjs/src/screen.o
npm ERR!   CC(target) Release/obj.target/robotjs/src/screengrab.o
npm ERR!   CC(target) Release/obj.target/robotjs/src/snprintf.o
npm ERR!   CC(target) Release/obj.target/robotjs/src/MMBitmap.o
npm ERR!   CC(target) Release/obj.target/robotjs/src/xdisplay.o
npm ERR!   SOLINK_MODULE(target) Release/obj.target/robotjs.node
npm ERR! make: Leaving directory '/home/alexei/coding-projects/repos/slither-bot/node_modules/robotjs/build'
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@9.0.0
npm ERR! gyp info using node@16.16.0 | linux | x64
npm ERR! gyp info find Python using Python version 3.10.4 found at "/usr/bin/python3"
npm ERR! gyp info spawn /usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/home/alexei/.nvm/versions/node/v16.16.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/home/alexei/coding-projects/repos/slither-bot/node_modules/robotjs/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/home/alexei/.nvm/versions/node/v16.16.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/home/alexei/.cache/node-gyp/16.16.0/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/home/alexei/.cache/node-gyp/16.16.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/home/alexei/.nvm/versions/node/v16.16.0/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/home/alexei/.cache/node-gyp/16.16.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/home/alexei/coding-projects/repos/slither-bot/node_modules/robotjs',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! cc1plus: warning: command-line option ‘-Wbad-function-cast’ is valid for C/ObjC but not for C++
npm ERR! In file included from ../src/robotjs.cc:1:
npm ERR! /home/alexei/.cache/node-gyp/16.16.0/include/node/node.h:847:7: warning: cast between incompatible function types from ‘void (*)(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)’ {aka ‘void (*)(v8::Local<v8::Object>)’} to ‘node::addon_register_func’ {aka ‘void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, void*)’} [-Wcast-function-type]
npm ERR!   847 |       (node::addon_register_func) (regfunc),                          
npm ERR!       |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm ERR! /home/alexei/.cache/node-gyp/16.16.0/include/node/node.h:881:3: note: in expansion of macro ‘NODE_MODULE_X’
npm ERR!   881 |   NODE_MODULE_X(modname, regfunc, NULL, 0)  // NOLINT (readability/null_usage)
npm ERR!       |   ^~~~~~~~~~~~~
npm ERR! ../src/robotjs.cc:907:1: note: in expansion of macro ‘NODE_MODULE’
npm ERR!   907 | NODE_MODULE(robotjs, InitAll)
npm ERR!       | ^~~~~~~~~~~
npm ERR! ../src/robotjs.cc: In function ‘Nan::NAN_METHOD_RETURN_TYPE keyToggle(Nan::NAN_METHOD_ARGS_TYPE)’:
npm ERR! ../src/robotjs.cc:592:38: warning: ‘down’ may be used uninitialized in this function [-Wmaybe-uninitialized]
npm ERR!   592 |                         toggleKeyCode(key, down, flags);
npm ERR!       |                         ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
npm ERR! In file included from ../../nan/nan_new.h:189,
npm ERR!                  from ../../nan/nan.h:294,
npm ERR!                  from ../src/robotjs.cc:2:
npm ERR! ../../nan/nan_implementation_12_inl.h: In function ‘void InitAll(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE)’:
npm ERR! ../../nan/nan_implementation_12_inl.h:119:1: warning: inlining failed in call to ‘static Nan::imp::FactoryBase<v8::FunctionTemplate>::return_t Nan::imp::Factory<v8::FunctionTemplate>::New.constprop(Nan::FunctionCallback, v8::Local<v8::Value>, v8::Local<v8::Signature>)’: --param large-function-growth limit reached [-Winline]
npm ERR!   119 | Factory<v8::FunctionTemplate>::New( FunctionCallback callback
npm ERR!       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm ERR! In file included from ../../nan/nan.h:294,
npm ERR!                  from ../src/robotjs.cc:2:
npm ERR! ../../nan/nan_new.h:239:32: note: called from here
npm ERR!   239 |     return imp::Factory<T>::New(callback, data);
npm ERR!       |            ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
npm ERR! In file included from ../../nan/nan_new.h:189,
npm ERR!                  from ../../nan/nan.h:294,
npm ERR!                  from ../src/robotjs.cc:2:
npm ERR! ../../nan/nan_implementation_12_inl.h:119:1: warning: inlining failed in call to ‘static Nan::imp::FactoryBase<v8::FunctionTemplate>::return_t Nan::imp::Factory<v8::FunctionTemplate>::New.constprop(Nan::FunctionCallback, v8::Local<v8::Value>, v8::Local<v8::Signature>)’: --param large-function-growth limit reached [-Winline]
npm ERR!   119 | Factory<v8::FunctionTemplate>::New( FunctionCallback callback
npm ERR!       | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
npm ERR! In file included from ../../nan/nan.h:294,
npm ERR!                  from ../src/robotjs.cc:2:
npm ERR! ../../nan/nan_new.h:239:32: note: called from here
npm ERR!   239 |     return imp::Factory<T>::New(callback, data);
npm ERR!       |            ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
npm ERR! ../src/keypress.c: In function ‘typeString’:
npm ERR! ../src/keypress.c:259:39: warning: ‘n’ may be used uninitialized in this function [-Wmaybe-uninitialized]
npm ERR!   259 |         #define toggleUniKey(c, down) toggleKey(c, down, MOD_NONE)
npm ERR!       |                                       ^~~~~~~~~
npm ERR! ../src/keypress.c:274:23: note: ‘n’ was declared here
npm ERR!   274 |         unsigned long n;
npm ERR!       |                       ^
npm ERR! ../src/snprintf.c: In function ‘portable_vsnprintf’:
npm ERR! ../src/snprintf.c:557:35: warning: operand of ‘?:’ changes signedness from ‘long int’ to ‘size_t’ {aka ‘long unsigned int’} due to unsignedness of other operand [-Wsign-compare]
npm ERR!   557 |       size_t n = !q ? strlen(p) : (q-p);
npm ERR!       |                                   ^~~~~
npm ERR! ../src/snprintf.c:704:42: warning: operand of ‘?:’ changes signedness from ‘long int’ to ‘size_t’ {aka ‘long unsigned int’} due to unsignedness of other operand [-Wsign-compare]
npm ERR!   704 |             str_arg_l = !q ? precision : (q-str_arg);
npm ERR!       |                                          ^~~~~~~~~~~
npm ERR! ../src/snprintf.c:943:62: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
npm ERR!   943 |             fast_memset(str+str_l, (zero_padding?'0':' '), (n>avail?avail:n));
npm ERR!       |                                                              ^
npm ERR! ../src/snprintf.c:372:35: note: in definition of macro ‘fast_memset’
npm ERR!   372 |   { register size_t nn = (size_t)(n); 
npm ERR!       |                                   ^
npm ERR! ../src/snprintf.c:943:75: warning: operand of ‘?:’ changes signedness from ‘int’ to ‘size_t’ {aka ‘long unsigned int’} due to unsignedness of other operand [-Wsign-compare]
npm ERR!   943 |             fast_memset(str+str_l, (zero_padding?'0':' '), (n>avail?avail:n));
npm ERR!       |                                                                           ^
npm ERR! ../src/snprintf.c:372:35: note: in definition of macro ‘fast_memset’
npm ERR!   372 |   { register size_t nn = (size_t)(n); 
npm ERR!       |                                   ^
npm ERR! ../src/snprintf.c:960:47: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
npm ERR!   960 |             fast_memcpy(str+str_l, str_arg, (n>avail?avail:n));
npm ERR!       |                                               ^
npm ERR! ../src/snprintf.c:365:35: note: in definition of macro ‘fast_memcpy’
npm ERR!   365 |   { register size_t nn = (size_t)(n); 
npm ERR!       |                                   ^
npm ERR! ../src/snprintf.c:960:60: warning: operand of ‘?:’ changes signedness from ‘int’ to ‘size_t’ {aka ‘long unsigned int’} due to unsignedness of other operand [-Wsign-compare]
npm ERR!   960 |             fast_memcpy(str+str_l, str_arg, (n>avail?avail:n));
npm ERR!       |                                                            ^
npm ERR! ../src/snprintf.c:365:35: note: in definition of macro ‘fast_memcpy’
npm ERR!   365 |   { register size_t nn = (size_t)(n); 
npm ERR!       |                                   ^
npm ERR! ../src/snprintf.c:969:43: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
npm ERR!   969 |             fast_memset(str+str_l, '0', (n>avail?avail:n));
npm ERR!       |                                           ^
npm ERR! ../src/snprintf.c:372:35: note: in definition of macro ‘fast_memset’
npm ERR!   372 |   { register size_t nn = (size_t)(n); 
npm ERR!       |                                   ^
npm ERR! ../src/snprintf.c:969:56: warning: operand of ‘?:’ changes signedness from ‘int’ to ‘size_t’ {aka ‘long unsigned int’} due to unsignedness of other operand [-Wsign-compare]
npm ERR!   969 |             fast_memset(str+str_l, '0', (n>avail?avail:n));
npm ERR!       |                                                        ^
npm ERR! ../src/snprintf.c:372:35: note: in definition of macro ‘fast_memset’
npm ERR!   372 |   { register size_t nn = (size_t)(n); 
npm ERR!       |                                   ^
npm ERR! ../src/snprintf.c:981:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
npm ERR!   981 |                         (n>avail?avail:n));
npm ERR!       |                           ^
npm ERR! ../src/snprintf.c:365:35: note: in definition of macro ‘fast_memcpy’
npm ERR!   365 |   { register size_t nn = (size_t)(n); 
npm ERR!       |                                   ^
npm ERR! ../src/snprintf.c:981:40: warning: operand of ‘?:’ changes signedness from ‘int’ to ‘size_t’ {aka ‘long unsigned int’} due to unsignedness of other operand [-Wsign-compare]
npm ERR!   981 |                         (n>avail?avail:n));
npm ERR!       |                                        ^
npm ERR! ../src/snprintf.c:365:35: note: in definition of macro ‘fast_memcpy’
npm ERR!   365 |   { register size_t nn = (size_t)(n); 
npm ERR!       |                                   ^
npm ERR! ../src/snprintf.c:992:43: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
npm ERR!   992 |             fast_memset(str+str_l, ' ', (n>avail?avail:n));
npm ERR!       |                                           ^
npm ERR! ../src/snprintf.c:372:35: note: in definition of macro ‘fast_memset’
npm ERR!   372 |   { register size_t nn = (size_t)(n); 
npm ERR!       |                                   ^
npm ERR! ../src/snprintf.c:992:56: warning: operand of ‘?:’ changes signedness from ‘int’ to ‘size_t’ {aka ‘long unsigned int’} due to unsignedness of other operand [-Wsign-compare]
npm ERR!   992 |             fast_memset(str+str_l, ' ', (n>avail?avail:n));
npm ERR!       |                                                        ^
npm ERR! ../src/snprintf.c:372:35: note: in definition of macro ‘fast_memset’
npm ERR!   372 |   { register size_t nn = (size_t)(n); 
npm ERR!       |                                   ^
npm ERR! ../src/snprintf.c:564:19: warning: variable ‘starting_p’ set but not used [-Wunused-but-set-variable]
npm ERR!   564 |       const char *starting_p;
npm ERR!       |                   ^~~~~~~~~~
npm ERR! ../src/snprintf.c:369:48: warning: ‘str_arg’ may be used uninitialized in this function [-Wmaybe-uninitialized]
npm ERR!   369 |       for (ss=(s), dd=(d); nn>0; nn--) *dd++ = *ss++; } }
npm ERR!       |                                                ^
npm ERR! ../src/snprintf.c:573:19: note: ‘str_arg’ was declared here
npm ERR!   573 |       const char *str_arg;      /* string address in case of string argument */
npm ERR!       |                   ^~~~~~~
npm ERR! ../src/xdisplay.c: In function ‘setXDisplay’:
npm ERR! ../src/xdisplay.c:53:23: warning: implicit declaration of function ‘strdup’ [-Wimplicit-function-declaration]
npm ERR!    53 |         displayName = strdup(name);
npm ERR!       |                       ^~~~~~
npm ERR! ../src/xdisplay.c:53:23: warning: incompatible implicit declaration of built-in function ‘strdup’ [-Wbuiltin-declaration-mismatch]
npm ERR! /usr/bin/ld: cannot find -lpng: No such file or directory
npm ERR! /usr/bin/ld: cannot find -lz: No such file or directory
npm ERR! collect2: error: ld returned 1 exit status
npm ERR! make: *** [robotjs.target.mk:173: Release/obj.target/robotjs.node] Error 1
npm ERR! gyp ERR! build error 
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/home/alexei/.nvm/versions/node/v16.16.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
npm ERR! gyp ERR! System Linux 5.15.0-43-generic
npm ERR! gyp ERR! command "/home/alexei/.nvm/versions/node/v16.16.0/bin/node" "/home/alexei/.nvm/versions/node/v16.16.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /home/alexei/coding-projects/repos/slither-bot/node_modules/robotjs
npm ERR! gyp ERR! node -v v16.16.0
npm ERR! gyp ERR! node-gyp -v v9.0.0
npm ERR! gyp ERR! not ok
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/alexei/.npm/_logs/2022-08-05T00_18_42_282Z-debug-0.log

根据ewong的评论,通过安装libpng和libz库解决了这个问题。

sudo apt-get install libpng-dev
sudo apt-get install zlib1g-dev

相关内容

最新更新