You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WSL环境安装near-cli后出现libusb初始化错误求助

解决WSL环境下near-cli运行时的libusb初始化错误

问题场景

在WSL环境(系统版本:Linux NT00654071 4.4.0-19041-Microsoft #3996-Microsoft Thu Jan 18 16:36:00 PST 2024 x86_64)中安装near-cli,执行npm install -g near-cli时收到版本弃用警告,更新240个包后,运行near --help出现以下错误:

Failed to initialize libusb.
/home/igor/.nvm/versions/node/v22.6.0/lib/node_modules/near-cli/node_modules/usb/dist/usb/index.js:30
Object.defineProperty(usb.Device.prototype, name, Object.getOwnPropertyDescriptor(device_1.ExtendedDevice.prototype, name) || Object.create(null));
^
TypeError: Cannot read properties of undefined (reading 'prototype')
at /home/igor/.nvm/versions/node/v22.6.0/lib/node_modules/near-cli/node_modules/usb/dist/usb/index.js:30:38
...(省略后续栈信息)

解决方案

1. 降级Node.js到LTS版本

Node.js v22属于最新稳定版,部分npm依赖包(如usb)尚未完成适配。使用nvm切换到LTS版本(推荐v20):

nvm install 20
nvm use 20

2. 安装WSL系统级libusb依赖

WSL默认未预装libusb开发库,需手动安装:

sudo apt update && sudo apt install libusb-1.0-0-dev

3. 重新安装near-cli

先卸载现有版本,再重新安装:

npm uninstall -g near-cli
npm install -g near-cli

备选方案:指定兼容的near-cli版本

如果上述步骤无效,可尝试安装已知适配的near-cli版本(比如v3.4.0):

npm install -g near-cli@3.4.0

内容的提问来源于stack exchange,提问作者Igor Walter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 17:23:16