Hyperledger Aries初始化时出现指定模块未找到错误求助
关于Hyperledger Aries JS Agent初始化时indy-sdk模块找不到的问题
已完成Aries.js官方初始化配置,使用以下代码初始化Agent:
//imports for indy-sdk import type { InitConfig } from '@aries-framework/core' import { Agent } from '@aries-framework/core' import { agentDependencies } from '@aries-framework/node' import { HttpOutboundTransport, WsOutboundTransport } from '@aries-framework/core' import { HttpInboundTransport } from '@aries-framework/node' // The agent initialization configuration const config: InitConfig = { label: 'docs-nodejs-agent', walletConfig: { id: 'wallet-id', key: 'testkey0000000000000000000000000', }, } // Creating an agent instance const agent = new Agent(config, agentDependencies) // Registering the required in- and outbound transports agent.registerOutboundTransport(new HttpOutboundTransport()) agent.registerInboundTransport(new HttpInboundTransport({ port: 3000 })) // Function to initialize the agent const initialize = async () => await agent.initialize().catch(console.error)
在Visual Studio 2022中运行(Node.js v19.0.1)时出现如下错误:
C:\Users\Tosat\Desktop\Ladon\LadonHyperledgerAries\node_modules\bindings\bindings.js:121 throw e; ^ Error: The specified module could not be found. \\?\C:\Users\Tosat\Desktop\Ladon\LadonHyperledgerAries\node_modules\indy-sdk\build\Release\indynodejs.node at Module._extensions..node (node:internal/modules/cjs/loader:1243:18) at Module.load (node:internal/modules/cjs/loader:1037:32) at Module._load (node:internal/modules/cjs/loader:878:12) at Module.require (node:internal/modules/cjs/loader:1061:19) at require (node:internal/modules/cjs/helpers:103:18) at bindings (C:\Users\Tosat\Desktop\Ladon\LadonHyperledgerAries\node_modules\bindings\bindings.js:112:48) at Object.<anonymous> (C:\Users\Tosat\Desktop\Ladon\LadonHyperledgerAries\node_modules\indy-sdk\src\indyBinding.js:1:37) at Module._compile (node:internal/modules/cjs/loader:1159:14) at Module._extensions..js (node:internal/modules/cjs/loader:1213:10) at Module.load (node:internal/modules/cjs/loader:1037:32) { code: 'ERR_DLOPEN_FAILED' } Node.js v19.0.1
注意:报错指向的C:\Users\Tosat\Desktop\Ladon\LadonHyperledgerAries\node_modules\indy-sdk\build\Release\indynodejs.node文件确实存在且路径正确。
解决方法
- 降级Node.js版本:indy-sdk对Node.js版本兼容性要求较高,v19属于非LTS版本,存在二进制模块适配问题。建议降级到v16或v18的LTS版本,重新安装依赖后尝试运行。
- 清理并重新安装依赖:
- 删除项目根目录下的
node_modules文件夹和package-lock.json文件 - 执行
npm cache clean --force清理npm缓存 - 重新执行
npm install安装所有依赖
- 删除项目根目录下的
- 安装系统必要组件:Windows环境下需确保安装了Visual C++ Redistributable for Visual Studio 2019(或更高版本)以及.NET Framework 4.8,这些组件是indy-sdk二进制文件运行的依赖。
- 验证二进制文件完整性:删除
node_modules/indy-sdk文件夹,重新执行npm install @hyperledger/indy-sdk单独安装该模块,确保二进制文件下载完整无损坏。 - 以管理员权限运行:打开Visual Studio 2022时选择“以管理员身份运行”,或者在终端中以管理员权限执行启动命令,避免权限不足导致模块加载失败。
内容的提问来源于stack exchange,提问作者Simone Tosatto
相关产品推荐
相关产品推荐

