当我 npm install johnny 5 时,它不会下载目录。当我尝试使用 johnny 5 piezo 示例运行我的 index.js 文件时,它只是不想运行。给我一个关于串口的错误。我尝试安装串口,没有用。还尝试重新安装 node 和 npm,但这也没有用。这是我的 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
});
});
这是它抛出的错误:
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'
]
}
此外,每当我尝试安装 npm 包时,我都会收到很多错误和警告。