如何解决Bruno工具加载@azure/identity等模块的报错问题?
问题描述
我尝试调用Azure APIM上暴露的REST服务,该服务受Azure KeyVault中存储的TLS证书保护。Node.js服务器上的JavaScript代码运行正常,但在Bruno工具中调用时加载失败,报错:
Error invoking remote method 'send-http-request': TypeError: Cannot read properties of undefined (reading 'fd')
问题源于以下两个导入语句:
const { DefaultAzureCredential } = require("@azure/identity"); const { SecretClient } = require("@azure/keyvault-secrets");
我已在Bruno.json中添加白名单配置:
"scripts": { "moduleWhitelist": ["crypto","jsonwebtoken","pem","fs","child_process","os","process","tls","assert","tty","azure/identity","azure/keyvault-secrets","jsonwebtoken"], "filesystemAccess": { "allow": true } }
解决办法
- 修正模块白名单的包名格式:Bruno的模块白名单需要完整的npm包名,当前配置里的
azure/identity和azure/keyvault-secrets格式错误,应改为@azure/identity和@azure/keyvault-secrets,与require语句中的包名保持一致。修正后的配置如下:"scripts": { "moduleWhitelist": ["crypto","jsonwebtoken","pem","fs","child_process","os","process","tls","assert","tty","@azure/identity","@azure/keyvault-secrets"], "filesystemAccess": { "allow": true } } - 排除SDK依赖干扰:如果修正包名后仍报错,可手动从KeyVault获取证书/密钥,在Bruno脚本中直接使用静态值测试,确认是否是Azure SDK与Bruno环境不兼容导致的问题。
- 更新Bruno版本:旧版本Bruno对Azure SDK模块的兼容性可能较差,更新到最新版本后重新测试调用。
- 转移认证逻辑到外部服务:若上述方法均无效,可将Azure KeyVault的认证逻辑迁移到你的Node.js后端,Bruno先调用后端接口获取凭证,再用该凭证请求APIM服务。
内容的提问来源于stack exchange,提问作者felfel
相关产品推荐
相关产品推荐

