Node.js – cannot find module ‘serialport’ using Node.js and Johnny-Five


I tried using Johnny-five and node.js to run a script for, using Leap Motion Controls. now when i try to run the script it says: (Error: Cannot find module 'serialport') I tried npm install -g serial-port it goes through then give me lots of (err) codes in red . how can i fix this ?

D:>node robotarm.js

    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)


then i try

D:>npm install serialport

it gives

npm WARN package.json github-url-from-git@1.1.1 No repository field.
npm http GET
npm http 304
npm http GET
npm http GET
npm http GET
npm http GET
npm http GET
npm http 304
npm http 304
npm http 304
npm http 304
npm http 304
npm http GET
npm http GET
npm http 304
npm http 304

> serialport@1.4.10 install D:\node_modules\serialport
> node-pre-gyp install --fallback-to-build

node-pre-gyp http GET
node-pre-gyp http 404
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
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
=" "--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
gz" "--hosted_path=
elease/" "--hosted_tarball=
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= --modul
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=
1.4.10/Release/ --hosted_tarball=
port/v1.4.10/Release/node-v14-win32-x64.tar.gz' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (D:\node_modules\serialp
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
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= --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:// --hosted_tarbal
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!
npm ERR! Additional logging details can be found in:
npm ERR!     D:\npm-debug.log
npm ERR! not ok code 0 

Best Solution

It's telling you that the version you requested in not available as a pre-built binary for your platform. Serial port access is a low-level system thing, so such a module can't be written in pure Javascript.

As documented in the installation instructions for that module (skip down to "Installation special cases":

You have to build the package on your machine. The module is written in C++, so you must install Visual Studio Express. The build scripts are written in Python, so you have to install Python. Or talk to the module creator and ask why he doesn't have binaries for your platform (he has a Gitter chat room).

Related Question