Sự cố khi cài đặt gói NPM Node.js


7

Tôi có Raspberry Pi Model B + và hiện tại tôi đang làm việc với phát triển web. Hôm nay, tôi đã biên dịch thành công mã nguồn của Node.js trên Raspberry Pi của mình và tôi đã quản lý để cài đặt nó mà không gặp rắc rối nào. Phiên bản Node.js hiện tại của tôi là phiên bản 0.8.16 đi kèm với trình quản lý mô-đun NPM (1.1,69). Khi tôi thử và cài đặt mô-đun loa (nút loa), tôi gặp một loạt lỗi. Tôi thực sự cần giúp đỡ với việc cài đặt mô-đun đặc biệt này.

Đây là lỗi NPM ném vào tôi:

root@raspberrypi:/# npm install speaker
npm http GET https://registry.npmjs.org/speaker
npm http 304 https://registry.npmjs.org/speaker
npm http GET https://registry.npmjs.org/bindings
npm http GET https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/nan
npm http GET https://registry.npmjs.org/readable-stream
npm http 304 https://registry.npmjs.org/readable-stream
npm http 304 https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/nan
npm http GET https://registry.npmjs.org/ms/0.6.2
npm http GET https://registry.npmjs.org/core-util-is
npm http GET https://registry.npmjs.org/isarray/0.0.1
npm http GET https://registry.npmjs.org/string_decoder
npm http GET https://registry.npmjs.org/inherits
npm http 304 https://registry.npmjs.org/core-util-is
npm http 304 https://registry.npmjs.org/isarray/0.0.1
npm http 304 https://registry.npmjs.org/ms/0.6.2
npm http 304 https://registry.npmjs.org/string_decoder
npm http 304 https://registry.npmjs.org/inherits

> speaker@0.2.2 install /node_modules/speaker
> node-gyp rebuild

gyp WARN EACCES user "root" does not have permission to access the dev dir "/roo                                                                                        t/.node-gyp/0.8.16"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/node_modules/s                                                                                        peaker/.node-gyp"
gyp http GET http://nodejs.org/dist/v0.8.16/node-v0.8.16.tar.gz
gyp http 200 http://nodejs.org/dist/v0.8.16/node-v0.8.16.tar.gz
make: Entering directory '/node_modules/speaker/build'
  CC(target) Release/obj.target/output/deps/mpg123/src/output/alsa.o
../deps/mpg123/src/output/alsa.c:19:28: fatal error: alsa/asoundlib.h: No such f                                                                                        ile or directory
compilation terminated.
deps/mpg123/output.target.mk:92: recipe for target 'Release/obj.target/output/de                                                                                        ps/mpg123/src/output/alsa.o' failed
make: *** [Release/obj.target/output/deps/mpg123/src/output/alsa.o] Error 1
make: Leaving directory '/node_modules/speaker/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_                                                                                        modules/node-gyp/lib/build.js:232:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:99:17)
gyp ERR! stack     at Process._handle.onexit (child_process.js:678:10)
gyp ERR! System Linux 3.12.35+
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/b                                                                                        in/node-gyp.js" "rebuild"
gyp ERR! cwd /node_modules/speaker
gyp ERR! node -v v0.8.16
gyp ERR! node-gyp -v v0.7.3
gyp ERR! not ok
npm ERR! speaker@0.2.2 install: `node-gyp rebuild`
npm ERR! `sh "-c" "node-gyp rebuild"` failed with 1
npm ERR!
npm ERR! Failed at the speaker@0.2.2 install script.
npm ERR! This is most likely a problem with the speaker package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls speaker
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.12.35+
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "speaker"
npm ERR! cwd /
npm ERR! node -v v0.8.16
npm ERR! npm -v 1.1.69
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /npm-debug.log
npm ERR! not ok code 0

Có vẻ như vấn đề bắt đầu khi NPM cố gắng thực hiện lệnh này:

node-gyp rebuild

Làm thế nào tôi có thể khắc phục vấn đề này?

Câu trả lời:


8

Tôi đã thấy điều này trước đây trên Pi, nơi các gói được biên dịch bởi gyp từ chối biên dịch hoặc cài đặt. Một phương pháp khắc phục vấn đề này là cài đặt nhị phân được biên dịch sẵn.

Để thực hiện việc này bắt đầu bằng cách đảm bảo rằng Pi của bạn được cập nhật bằng cách nhập thông tin sau vào thiết bị đầu cuối:

sudo apt-get update && sudo apt-get upgrade

nút tải xuống tiếp theo (điều này sẽ tải xuống gói ổn định mới nhất):

wget http://node-arm.herokuapp.com/node_latest_armhf.deb

sau đó cài đặt gói:

sudo dpkg -i node_latest_armhf.deb

kiểm tra cài đặt có hoạt động không (lệnh sau sẽ trả về số phiên bản của nút):

node -v

bạn cũng có thể muốn kiểm tra phiên bản npm:

npm -v

tham khảo: https://learn.adafbean.com/node-embedded-development/installing-node-dot-js


6

Bạn nên cài đặt libasound2 trước:

sudo apt-get install libasound2-dev

Cảm ơn bạn!!!!! Đây là câu trả lời. Tôi không biết làm thế nào câu trả lời khác có thể làm việc. Nhưng tôi đoán có những vấn đề khác ngoài gói bị thiếu.
func0der
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.