質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

Raspberry Pi

Raspberry Piは、ラズベリーパイ財団が開発した、名刺サイズのLinuxコンピュータです。 学校で基本的なコンピュータ科学の教育を促進することを意図しています。

Q&A

2回答

673閲覧

(Node.js)ラズパイでのbleのrssiを取得するプログラムのmoduleエラー

aiai8976

総合スコア112

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

Raspberry Pi

Raspberry Piは、ラズベリーパイ財団が開発した、名刺サイズのLinuxコンピュータです。 学校で基本的なコンピュータ科学の教育を促進することを意図しています。

0グッド

0クリップ

投稿2019/10/29 07:43

編集2022/01/12 10:55

前提・実現したいこと

macでbleのrssiを取得するプログラムを作り、ラズパイに移行しようとしましたが、以下のようなエラーが発生しています。
mac側のpackage.josnとpackage-lock.json、node_modulesファイルを移行して、npm install後に実行しました。
nodeのバージョンはmacでやった時と合わせています。
解決策がわかる方がいましたらコメントお願いします。

発生している問題・エラーメッセージ

pi@raspberrypi:~/Desktop/kenkyu/raspi/rssi $ sudo node rssi_sample.js internal/modules/cjs/loader.js:1003 return process.dlopen(module, path.toNamespacedPath(filename)); ^ Error: The module '/home/pi/Desktop/kenkyu/raspi/rssi/node_modules/bluetooth-hci-socket/build/Release/binding.node' was compiled against a different Node.js version using NODE_MODULE_VERSION 57. This version of Node.js requires NODE_MODULE_VERSION 72. Please try re-compiling or re-installing the module (for instance, using `npm rebuild` or `npm install`). at Object.Module._extensions..node (internal/modules/cjs/loader.js:1003:18) at Module.load (internal/modules/cjs/loader.js:812:32) at Function.Module._load (internal/modules/cjs/loader.js:724:14) at Module.require (internal/modules/cjs/loader.js:849:19) at require (internal/modules/cjs/helpers.js:74:18) at Object.<anonymous> (/home/pi/Desktop/kenkyu/raspi/rssi/node_modules/bluetooth-hci-socket/lib/native.js:3:15) at Module._compile (internal/modules/cjs/loader.js:956:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10) at Module.load (internal/modules/cjs/loader.js:812:32) at Function.Module._load (internal/modules/cjs/loader.js:724:14)

npm install

$ npm install > usb@1.6.0 install /home/pi/Desktop/kenkyu/raspi/rssi/node_modules/usb > prebuild-install --verbose || node-gyp rebuild prebuild-install info begin Prebuild-install version 5.3.2 prebuild-install info looking for cached prebuild @ /home/pi/.npm/_prebuilds/d16678-usb-v1.6.0-node-v57-linux-arm.tar.gz prebuild-install http request GET https://github.com/tessel/node-usb/releases/download/v1.6.0/usb-v1.6.0-node-v57-linux-arm.tar.gz prebuild-install http 404 https://github.com/tessel/node-usb/releases/download/v1.6.0/usb-v1.6.0-node-v57-linux-arm.tar.gz prebuild-install WARN install No prebuilt binaries found (target=8.9.4 runtime=node arch=arm libc= platform=linux) make: ディレクトリ '/home/pi/Desktop/kenkyu/raspi/rssi/node_modules/usb/build' に入ります CC(target) Release/obj.target/libusb/libusb/libusb/core.o CC(target) Release/obj.target/libusb/libusb/libusb/descriptor.o CC(target) Release/obj.target/libusb/libusb/libusb/hotplug.o CC(target) Release/obj.target/libusb/libusb/libusb/io.o CC(target) Release/obj.target/libusb/libusb/libusb/strerror.o CC(target) Release/obj.target/libusb/libusb/libusb/sync.o CC(target) Release/obj.target/libusb/libusb/libusb/os/poll_posix.o CC(target) Release/obj.target/libusb/libusb/libusb/os/threads_posix.o CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_usbfs.o CC(target) Release/obj.target/libusb/libusb/libusb/os/linux_udev.o ../libusb/libusb/os/linux_udev.c:40:21: fatal error: libudev.h: そのようなファイルやディレクトリはありません #include <libudev.h> ^ compilation terminated. libusb.target.mk:132: ターゲット 'Release/obj.target/libusb/libusb/libusb/os/linux_udev.o' のレシピで失敗しました make: *** [Release/obj.target/libusb/libusb/libusb/os/linux_udev.o] エラー 1 make: ディレクトリ '/home/pi/Desktop/kenkyu/raspi/rssi/node_modules/usb/build' から出ます gyp ERR! build error gyp ERR! stack Error: `make` failed with exit code: 2 gyp ERR! stack at ChildProcess.onExit (/home/pi/.nodebrew/node/v8.9.4/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23) gyp ERR! stack at emitTwo (events.js:126:13) gyp ERR! stack at ChildProcess.emit (events.js:214:7) gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12) gyp ERR! System Linux 4.14.98-v7+ gyp ERR! command "/home/pi/.nodebrew/node/v8.9.4/bin/node" "/home/pi/.nodebrew/node/v8.9.4/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /home/pi/Desktop/kenkyu/raspi/rssi/node_modules/usb gyp ERR! node -v v8.9.4 gyp ERR! node-gyp -v v3.6.2 gyp ERR! not ok npm WARN noble_lesson@1.0.0 No description npm WARN noble_lesson@1.0.0 No repository field. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: usb@1.6.0 (node_modules/usb): npm WARN optional SKIPPING OPTIONAL DEPENDENCY: usb@1.6.0 install: `prebuild-install --verbose || node-gyp rebuild` npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1 up to date in 42.583s

該当のソースコード

rssi_sample.js

'use strict'; //const noble = require('noble-mac'); const noble = require('noble'); //npm install nobleをする必要あり const fs = require('fs'); function asyncFunc(rssi) { return new Promise((resolve) => { // ...何かしらの時間がかかる処理... let result; console.log(rssi); fs.appendFile('out.csv', ',' + rssi, (error) => { result = "csvファイルに出力しました"; resolve(result); }) }); } //BLE deviceをさがす。 const discovered = async (peripheral) => { console.log(`BLE Device Found: ${peripheral.advertisement.localName}(${peripheral.uuid}) RSSI${peripheral.rssi}`); if (peripheral.advertisement.localName === 'BlueJelly') { noble.stopScanning(); let text = await asyncFunc(peripheral.rssi); noble.stopScanning(); console.log(text); console.log('device found'); } } //スキャン開始 const scanStart = () => { noble.startScanning(); noble.on('discover', discovered); } if (noble.state === 'poweredOn') { scanStart(); } else { noble.on('stateChange', scanStart); }
pi@raspberrypi:~/Desktop/kenkyu/raspi/rssi $ tree -L 2 . ├── node_modules │   ├── abbrev │   ├── ansi-regex │   ├── aproba │   ├── are-we-there-yet │   ├── async │   ├── balanced-match │   ├── bluetooth-hci-socket │   ├── bplist-parser │   ├── brace-expansion │   ├── chownr │   ├── clone │   ├── code-point-at │   ├── concat-map │   ├── console-control-strings │   ├── core-util-is │   ├── cross-spawn │   ├── csv │   ├── csv-generate │   ├── csv-parse │   ├── csv-stringify │   ├── debug │   ├── deep-extend │   ├── defaults │   ├── delegates │   ├── detect-libc │   ├── fluent-ffmpeg │   ├── fs-minipass │   ├── fs.realpath │   ├── gauge │   ├── glob │   ├── has-unicode │   ├── iconv-lite │   ├── ignore-walk │   ├── inflight │   ├── inherits │   ├── ini │   ├── is-fullwidth-code-point │   ├── isarray │   ├── isexe │   ├── minimatch │   ├── minimist │   ├── minipass │   ├── minizlib │   ├── mixme │   ├── mkdirp │   ├── ms │   ├── nan │   ├── napi-thread-safe-callback │   ├── needle │   ├── nice-try │   ├── noble │   ├── noble-mac │   ├── node-addon-api │   ├── node-bebop │   ├── node-pre-gyp │   ├── node_modules │   ├── nopt │   ├── npm-bundled │   ├── npm-packlist │   ├── npmlog │   ├── number-is-nan │   ├── object-assign │   ├── once │   ├── os-homedir │   ├── os-tmpdir │   ├── osenv │   ├── pad │   ├── path-is-absolute │   ├── path-key │   ├── process-nextick-args │   ├── rc │   ├── readable-stream │   ├── rimraf │   ├── safe-buffer │   ├── safer-buffer │   ├── sax │   ├── semver │   ├── set-blocking │   ├── shebang-command │   ├── shebang-regex │   ├── signal-exit │   ├── storotype │   ├── stream-transform │   ├── string-width │   ├── string_decoder │   ├── strip-ansi │   ├── strip-json-comments │   ├── tar │   ├── through │   ├── util-deprecate │   ├── wcwidth │   ├── which │   ├── wide-align │   ├── wrappy │   ├── xpc-connection │   └── yallist ├── package-lock.json ├── package.json ├── rssi_sample.js └── tello.js

補足情報(FW/ツールのバージョンなど)

node v8.9.4
npm v5.6.0

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

node_modulesは生成されるものであり、あまり直接コピーしないほうが良いらしいです

投稿2019/10/29 15:20

zma3

総合スコア39

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

node_modulesとpackage-lock.jsonをrm -rf などで削除してからもう一度npm installをし起動したらどうでしょうか?

投稿2019/10/29 15:14

zma3

総合スコア39

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

aiai8976

2019/10/29 22:26

node_modulesは一回消して試してみましたが、変わりませんでした。 package-lock.jsonも関係ありますか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問