{ // Create an Led on pin 13 const " /> { // Create an Led on pin 13 const " /> { // Create an Led on pin 13 const "/>

Error: Cannot find module 'serialport' Johnny-five node package

438 Views Asked by At

My code is this

const { Board, Led } = require("johnny-five");
const board = new Board();

board.on("ready", () =\> {
// Create an Led on pin 13
const led = new Led(13);
// Blink every half second
led.blink(500);
});

And the error I'm getting is this

Error: Cannot find module 'serialport'
Require stack:
- A:\Projects\Web\Arduino\node_modules\johnny-five\lib\board.js
- A:\Projects\Web\Arduino\node_modules\johnny-five\lib\accelerometer.js  
- A:\Projects\Web\Arduino\node_modules\johnny-five\lib\johnny-five.js    
- A:\Projects\Web\Arduino\app.js

I tried to install serialport and after installing I get this error


TypeError: serialport.list is not a function
    at Board.detect (A:\Projects\Web\Arduino\node_modules\johnny-five\lib\board.js:42:16)
    at new Board (A:\Projects\Web\Arduino\node_modules\johnny-five\lib\board.js:291:23)
    at Object.<anonymous> (A:\Projects\Web\Arduino\app.js:2:15)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)        
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)   
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47
[nodemon] app crashed - waiting for file changes before starting...
    

I also tried this code.

var five = require("johnny-five");

var board = new five.Board({ port: "COM22" });

board.on("ready", function(){
    var lead = new five.Led(13);

    lead.blink(1000);
})

Then I get this error.

Error: Cannot find module 'firmata'

And when I try to install firmata I get this error

npm ERR! code 1 npm ERR! path C:\Users\username Mengistu\AppData\Roaming\npm\node_modules\firmata\node_modules@serialport\bindings npm ERR! command failed npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild npm ERR! gyp info it worked if it ends with ok npm ERR! gyp info using [email protected] npm ERR! gyp info using [email protected] | win32 | x64 npm ERR! gyp info find Python using Python version 3.10.5 found at "C:\Users\username Mengistu\AppData\Local\Programs\Python\Python310\python.exe"npm ERR! gyp ERR! find VS npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt npm ERR! gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more detailsnpm ERR! gyp ERR! find VS looking for Visual Studio 2015 npm ERR! gyp ERR! find VS - not found npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8 npm ERR! gyp ERR! find VS npm ERR! gyp ERR! find VS ************************************************************** npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload. npm ERR! gyp ERR! find VS For more information consult the documentation at: npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windowsnpm ERR! gyp ERR! find VS ************************************************************** npm ERR! gyp ERR! find VS npm ERR! gyp ERR! configure error npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use npm ERR! gyp ERR! stack     at VisualStudioFinder.fail (C:\Users\username Mengistu\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:122:47) npm ERR! gyp ERR! stack     at C:\Users\username Mengistu\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:75:16 npm ERR! gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\username Mengistu\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:363:14)npm ERR! gyp ERR! stack     at C:\Users\username Mengistu\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:71:14 npm ERR! gyp ERR! stack     at C:\Users\username Mengistu\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:384:16 npm ERR! gyp ERR! stack     at C:\Users\username Mengistu\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7 npm ERR! gyp ERR! stack     at C:\Users\username Mengistu\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16 npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:406:5) npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:520:28) npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1092:16) npm ERR! gyp ERR! System Windows_NT 10.0.19044 npm ERR! gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\username Mengistu\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild" npm ERR! gyp ERR! cwd C:\Users\username Mengistu\AppData\Roaming\npm\node_modules\firmata\node_modules@serialport\bindings npm ERR! gyp ERR! node -v v16.14.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!     C:\Users\username Mengistu\AppData\Local\npm-cache_logs\2022-10-28T08_17_34_241Z-debug-0.log
1

There are 1 best solutions below

0
ISHIMWE Isaac On

I have been facing the same type error for 3 weeks now but what I did is I installed build-essential package on my Ubuntu OS, deleted package-lock.json, and node_modules in my project and run npm install. That worked. if you are on windows run npm install -g windows-build-tools then make sure johnny-five is installed in your project. No need of changing node version to an early versions as some people suggest on the internet.

My code in index.js looks like this.

const { Board, Led } = require("johnny-five");
const board = new Board();

board.on("ready", () => {
  const led = new Led(13);

  led.blink(500);
});

Helpful links

  1. My package.json file as well as the run program result

  2. build-essential package on Ubuntu OS explanation and installation

  3. Official Windows-Build-Tools installation guide