0

When I npm install johnny five it doesnt download a directory. When I try to run my index.js file with johnny five piezo example it just doesnt want to run. Gives me an error about serialport. I tried installing serialport, didnt work. Also tried reainstalling node and npm but that also didnt work. Here is my index.js:

var five = require("johnny-five"),
  board = new five.Board();

board.on("ready", function() {
  // Creates a piezo object and defines the pin to be used for the signal
  var piezo = new five.Piezo(3);

  // Injects the piezo into the repl
  board.repl.inject({
    piezo: piezo
  });

  // Plays a song
  piezo.play({
    // song is composed by an array of pairs of notes and beats
    // The first argument is the note (null means "no note")
    // The second argument is the length of time (beat) of the note (or non-note)
    song: [
      ["C4", 1 / 4],
      ["D4", 1 / 4],
      ["F4", 1 / 4],
      ["D4", 1 / 4],
      ["A4", 1 / 4],
      [null, 1 / 4],
      ["A4", 1],
      ["G4", 1],
      [null, 1 / 2],
      ["C4", 1 / 4],
      ["D4", 1 / 4],
      ["F4", 1 / 4],
      ["D4", 1 / 4],
      ["G4", 1 / 4],
      [null, 1 / 4],
      ["G4", 1],
      ["F4", 1],
      [null, 1 / 2]
    ],
    tempo: 100
  });

  // Plays the same song with a string representation
  piezo.play({
    // song is composed by a string of notes
    // a default beat is set, and the default octave is used
    // any invalid note is read as "no note"
    song: "C D F D A - A A A A G G G G - - C D F D G - G G G G F F F F - -",
    beats: 1 / 4,
    tempo: 100
  });

});

and here are the errors that it threw:

PS C:\Users\Krisztian\Desktop\proba> node index.js
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module '@serialport/bindings'
Require stack:
- C:\Users\Krisztian\node_modules\serialport\lib\index.js
- C:\Users\Krisztian\node_modules\johnny-five\lib\board.js
- C:\Users\Krisztian\node_modules\johnny-five\lib\accelerometer.js
- C:\Users\Krisztian\node_modules\johnny-five\lib\johnny-five.js
- C:\Users\Krisztian\Desktop\proba\index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (C:\Users\Krisztian\node_modules\serialport\lib\index.js:2:17)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Users\\Krisztian\\node_modules\\serialport\\lib\\index.js',
    'C:\\Users\\Krisztian\\node_modules\\johnny-five\\lib\\board.js',
    'C:\\Users\\Krisztian\\node_modules\\johnny-five\\lib\\accelerometer.js',
    'C:\\Users\\Krisztian\\node_modules\\johnny-five\\lib\\johnny-five.js',
    'C:\\Users\\Krisztian\\Desktop\\proba\\index.js'
  ]
}

Also whenever im trying to install npm packages i get a lot of errors and warnings.

Dkrisztan
  • 11
  • 1
  • You can see from the stack trace whats happening, [\johnny-five\lib\board.js](https://github.com/rwaldron/johnny-five/blob/master/lib/board.js#L35) wants [serialport](https://www.npmjs.com/package/serialport), that wants [@serialport/bindings](https://www.npmjs.com/package/@serialport/bindings). Please show your package.json – Lawrence Cherone Nov 11 '20 at 21:39
  • @LawrenceCherone there is none created. Should I create one manually? – Dkrisztan Nov 11 '20 at 21:41
  • yeah, then you can add packages you need, it looks like you installed it into your user node_modules and it's not picking up the bindings package as a dep.. do `npm init` where the index.js is, then install both them packages `npm i johnny-five @serialport/bindings`, then should probably work – Lawrence Cherone Nov 11 '20 at 21:46
  • @LawrenceCherone thanks for the kind help, i eventually installed the windows tool thingies and for some reason it works now. I appreciate the help anyways, it has been strugling me for the past hour and a half. Thank you:) – Dkrisztan Nov 11 '20 at 21:48
  • np, `C:\\Users\\Krisztian\\node_modules` is the clue.. everything needed for the project should be in `C:\\Users\\Krisztian\\Desktop\\proba\\node_modules` – Lawrence Cherone Nov 11 '20 at 21:49

0 Answers0