我尝试使用Johnny-five和node.js使用Leap Motion Controls运行脚本。现在,当我尝试运行脚本时,它说:(错误:找不到模块'serialport')我试过npm install -g serial-port它经过然后给我很多(错)代码为红色。我该如何解决这个问题?
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)
然后我尝试
它给出了
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
答案 0 :(得分:4)
它告诉您,您请求的版本不可用作您平台的预构建二进制文件。串口访问是一个低级系统的事情,所以这样的模块不能用纯Javascript编写。
如该模块的安装说明中所述(跳到“安装特殊情况”:
https://github.com/voodootikigod/node-serialport
您必须在计算机上构建程序包。该模块是用C ++编写的,因此您必须安装Visual Studio Express。构建脚本是用Python编写的,因此您必须安装Python。或者与模块创建者交谈并询问为什么他没有为您的平台提供二进制文件(他有一个Gitter聊天室)。
答案 1 :(得分:0)
问题解决了:)
如果有人有问题。然后安装visual studio,python然后npm install serialport
cd node_modules
cd serialport
node-pre-gyp rebuild