使用Node.js和Johnny-Five无法find模块'serialport'

我尝试使用Johnny-five和node.js来运行Leap Motion Controls的脚本。 现在,当我尝试运行脚本它说:(错误:找不到模块'serialport')我试过npm安装-g串行端口它通过然后给我很多(错误)代码在红色。 我怎样才能解决这个问题 ?

D:>节点robotarm.js

module.js:338 throw err; ^ Error: Cannot find module 'serialport' at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:278:25) at Module.require (module.js:365:17) at require (module.js:384:17) at Board.Serial.detect (D:\node_modules\johnny-five\lib\board.js:70:7) at new Board (D:\node_modules\johnny-five\lib\board.js:303:23) at Object.<anonymous> (D:\robotarm.js:90:9) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) 

然后我尝试

D:> npm安装serialport

它给

 npm WARN package.json github-url-from-git@1.1.1 No repository field. npm http GET https://registry.npmjs.org/serialport npm http 304 https://registry.npmjs.org/serialport npm http GET https://registry.npmjs.org/optimist npm http GET https://registry.npmjs.org/sf npm http GET https://registry.npmjs.org/nan npm http GET https://registry.npmjs.org/bindings npm http GET https://registry.npmjs.org/async npm http 304 https://registry.npmjs.org/optimist npm http 304 https://registry.npmjs.org/async npm http 304 https://registry.npmjs.org/bindings npm http 304 https://registry.npmjs.org/sf npm http 304 https://registry.npmjs.org/nan npm http GET https://registry.npmjs.org/wordwrap npm http GET https://registry.npmjs.org/minimist npm http 304 https://registry.npmjs.org/wordwrap npm http 304 https://registry.npmjs.org/minimist > serialport@1.4.10 install D:\node_modules\serialport > node-pre-gyp install --fallback-to-build node-pre-gyp http GET https://node-serialport.s3.amazonaws.com/serialport/v1.4.1 0/Release/node-v14-win32-x64.tar.gz node-pre-gyp http 404 https://node-serialport.s3.amazonaws.com/serialport/v1.4.1 0/Release/node-v14-win32-x64.tar.gz node-pre-gyp http Pre-built binary not available for your system (falling back t o source compile with node-gyp) child_process: customFds option is deprecated, use stdio instead. gyp ERR! configure error gyp ERR! stack Error: Can't find Python executable "python", you can set the PYT HON env variable. gyp ERR! stack at failNoPython (D:\node_modules\node-gyp\lib\configure.js:10 3:14) gyp ERR! stack at D:\node_modules\node-gyp\lib\configure.js:64:11 gyp ERR! stack at FSReqWrap.oncomplete (fs.js:99:15) gyp ERR! System Windows_NT 6.1.7601 gyp ERR! command "C:\\Program Files (x86)\\nodejs\\node.exe" "D:\\node_modules\\ node-gyp\\bin\\node-gyp.js" "rebuild" "--name=serialport" "--configuration=Relea se" "--module_name=serialport" "--version=1.4.10" "--major=1" "--minor=4" "--pat ch=10" "--runtime=node" "--node_abi=node-v14" "--platform=win32" "--target_platf orm=win32" "--arch=x64" "--target_arch=x64" "--module_main=./serialport" "--host =https://node-serialport.s3.amazonaws.com/" "--module_path=D:\\node_modules\\ser ialport\\build\\serialport\\v1.4.10\\Release\\node-v14-win32-x64" "--remote_path =./serialport/v1.4.10/Release/" "--package_name=node-v14-win32-x64.tar.gz" "--st aged_tarball=build\\stage\\serialport\\v1.4.10\\Release\\node-v14-win32-x64.tar. gz" "--hosted_path=https://node-serialport.s3.amazonaws.com/serialport/v1.4.10/R elease/" "--hosted_tarball=https://node-serialport.s3.amazonaws.com/serialport/v 1.4.10/Release/node-v14-win32-x64.tar.gz" gyp ERR! cwd D:\node_modules\serialport gyp ERR! node -v v0.12.0 gyp ERR! node-gyp -v v0.13.0 gyp ERR! not ok node-pre-gyp ERR! build error node-pre-gyp ERR! stack Error: Failed to execute 'C:\Program Files (x86)\nodejs\ node.exe rebuild --name=serialport --configuration=Release --module_name=serialp ort --version=1.4.10 --major=1 --minor=4 --patch=10 --runtime=node --node_abi=no de-v14 --platform=win32 --target_platform=win32 --arch=x64 --target_arch=x64 --m odule_main=./serialport --host=https://node-serialport.s3.amazonaws.com/ --modul e_path=D:\node_modules\serialport\build\serialport\v1.4.10\Release\node-v14-win3 2-x64 --remote_path=./serialport/v1.4.10/Release/ --package_name=node-v14-win32- x64.tar.gz --staged_tarball=build\stage\serialport\v1.4.10\Release\node-v14-win3 2-x64.tar.gz --hosted_path=https://node-serialport.s3.amazonaws.com/serialport/v 1.4.10/Release/ --hosted_tarball=https://node-serialport.s3.amazonaws.com/serial port/v1.4.10/Release/node-v14-win32-x64.tar.gz' (1) node-pre-gyp ERR! stack at ChildProcess.<anonymous> (D:\node_modules\serialp ort\node_modules\node-pre-gyp\lib\util\compile.js:76:29) node-pre-gyp ERR! stack at ChildProcess.emit (events.js:110:17) node-pre-gyp ERR! stack at maybeClose (child_process.js:1008:16) node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (child_proces s.js:1080:5) node-pre-gyp ERR! System Windows_NT 6.1.7601 node-pre-gyp ERR! command "node" "D:\\node_modules\\serialport\\node_modules\\no de-pre-gyp\\bin\\node-pre-gyp" "install" "--fallback-to-build" node-pre-gyp ERR! cwd D:\node_modules\serialport node-pre-gyp ERR! node -v v0.12.0 node-pre-gyp ERR! node-pre-gyp -v v0.5.19 node-pre-gyp ERR! not ok Failed to execute 'C:\Program Files (x86)\nodejs\node.exe rebuild --name=serialp ort --configuration=Release --module_name=serialport --version=1.4.10 --major=1 --minor=4 --patch=10 --runtime=node --node_abi=node-v14 --platform=win32 --targe t_platform=win32 --arch=x64 --target_arch=x64 --module_main=./serialport --host= https://node-serialport.s3.amazonaws.com/ --module_path=D:\node_modules\serialpo rt\build\serialport\v1.4.10\Release\node-v14-win32-x64 --remote_path=./serialpor t/v1.4.10/Release/ --package_name=node-v14-win32-x64.tar.gz --staged_tarball=bui ld\stage\serialport\v1.4.10\Release\node-v14-win32-x64.tar.gz --hosted_path=http s://node-serialport.s3.amazonaws.com/serialport/v1.4.10/Release/ --hosted_tarbal l=https://node-serialport.s3.amazonaws.com/serialport/v1.4.10/Release/node-v14-w in32-x64.tar.gz' (1) npm ERR! serialport@1.4.10 install: `node-pre-gyp install --fallback-to-build` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the serialport@1.4.10 install script. npm ERR! This is most likely a problem with the serialport package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! node-pre-gyp install --fallback-to-build npm ERR! You can get their info via: npm ERR! npm owner ls serialport npm ERR! There is likely additional logging output above. npm ERR! System Windows_NT 6.1.7601 npm ERR! command "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program File s (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "serialport" npm ERR! cwd D:\ npm ERR! node -v v0.12.0 npm ERR! npm -v 1.4.9 npm ERR! code ELIFECYCLE npm ERR! npm ERR! Additional logging details can be found in: npm ERR! D:\npm-debug.log npm ERR! not ok code 0 

它告诉你,你所请求的版本不能作为你的平台的预build二进制文件。 串口访问是一个低层次的系统事物,所以这样的模块不能用纯Javascript编写。

如该模块的安装说明中所述(跳至“安装特殊情况”:

 https://github.com/voodootikigod/node-serialport 

您必须在您的机器上构build软件包。 该模块是用C ++编写的,所以你必须安装Visual Studio Express。 构build脚本是用Python编写的,所以你必须安装Python。 或者与模块创build者交谈,问他为什么没有为你的平台准备好二进制文件(他有一个Gitter聊天室)。

问题解决了:)如果有人有问题。 安装Visual Studio,Python然后npm install serialport然后cd node_modules cd serialport node-pre-gyp rebuild cd serialport node-pre-gyp rebuild