【AGC】HarmonyOS鸿蒙Next中按照官方指导写的代码遇到如下报错 - 在nodejs函数中访问clouddb

【AGC】HarmonyOS鸿蒙Next中按照官方指导写的代码遇到如下报错 - 在nodejs函数中访问clouddb

依赖的版本:

"dependencies": {
  "@agconnect/database-server": "^1.0.2"
}

函数代码(在nodejs函数中访问clouddb):

var api_client_name = "./resources/agc-apiclient-xx.json";
var api_client_path = path.join(__dirname, api_client_name);
AGCClient.initialize(CredentialParser.toCredential(api_client_path));
clouddb.AGConnectCloudDB.initialize(AGCClient.getInstance());

函数运行报错:

{
  "code": 180000,
  "message": "Call handler error: TypeError: Cannot read property 'getCommonConfiguration' of undefined\n at Function.CloudDBSdkUtils.getCloudGwUrl (/dcache/layer/func/node_modules/@agconnect/database-server/dist/utils/CloudDBSdkUtils.js:34:56)\n at new HttpsCommunicator (/dcache/layer/func/node_modules/@agconnect/database-server/dist/communicator/https/HttpsCommunicator.js:79:64)\n at AGConnectCloudDB.CloudDBService (/dcache/layer/func/node_modules/@agconnect/database-server/dist/services/CloudDBService.js:29:30)\n at new AGConnectCloudDB (/dcache/layer/func/node_modules/@agconnect/database-server/dist/services/AGConnectCloudDB.js:31:28)\n at Function.AGConnectCloudDB.initialize (/dcache/layer/func/node_modules/@agconnect/database-server/dist/services/AGConnectCloudDB.js:49:37)\n at Object.<anonymous> (/dcache/layer/func/handler.js:16:26)\n at Module._compile (internal/modules/cjs/loader.js:1063:30)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)\n at Module.load (internal/modules/cjs/loader.js:928:32)\n at Function.Module._load (internal/modules/cjs/loader.js:769:14)"
}

更多关于【AGC】HarmonyOS鸿蒙Next中按照官方指导写的代码遇到如下报错 - 在nodejs函数中访问clouddb的实战教程也可以访问 https://www.itying.com/category-93-b0.html

8 回复

是wisefunction.zip吗?请问解决了吗?我好像也遇到这个问题

更多关于【AGC】HarmonyOS鸿蒙Next中按照官方指导写的代码遇到如下报错 - 在nodejs函数中访问clouddb的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


开发者您好,我们的示例代码和你们写的有些出入,请检查一下agc-apiclient-xxxx.json这个文件有没有读取成功呢?

const credentialPath = “resource\agc-apiclient-xxxx.json”;

agconnect.AGCClient.initialize(agconnect.CredentialParser.toCredential(credentialPath));

const agcClient = agconnect.AGCClient.getInstance();

按照你这个写法才会报找不到文件的错误:

AGCError: 10603: agc client credential fail, file not exist

我试过的代码,你这种错误写法我注释掉了,请根据原文的报错看下 getCommonConfiguration 符号到底在哪儿吧:

var credentialPath = "./resources/agc-apiclient-782636521067924608-7041897582951343204.json";
var credentialPathA = path.join(__dirname, credentialPath);
AGCClient.initialize(CredentialParser.toCredential(credentialPathA));

// var credentialPathO = "resources\\agc-apiclient-782636521067924608-7041897582951343204.json";
// AGCClient.initialize(CredentialParser.toCredential(credentialPathO));
clouddb.AGConnectCloudDB.initialize(AGCClient.getInstance());

您好,相关问题已经反馈给工作人员,请耐心等待,感谢您对华为开发者论坛的支持。

问题没有解决~

在HarmonyOS鸿蒙Next中,使用Node.js函数访问CloudDB时,可能会遇到报错。报错原因通常与CloudDB的配置、权限或网络连接有关。首先,确保CloudDB实例已正确创建,并且Node.js函数具有访问该实例的权限。其次,检查CloudDB的访问地址和端口是否正确配置。如果使用HTTPS协议,确保SSL证书已正确安装。此外,检查网络连接是否正常,确保Node.js函数能够访问CloudDB实例。如果问题仍未解决,可以查看CloudDB的日志,获取更多错误信息。

在HarmonyOS鸿蒙Next中,如果你在Node.js函数中访问CloudDB时遇到报错,可能是由于以下原因:

  1. 权限问题:确保你的应用已正确配置CloudDB的访问权限,并在config.json中声明了相关权限。

  2. SDK版本不匹配:检查你使用的Node.js SDK和CloudDB SDK版本是否兼容,建议使用官方推荐的最新版本。

  3. 初始化问题:确保在访问CloudDB之前,已正确初始化CloudDB客户端,并配置了正确的项目ID和密钥。

  4. 网络问题:检查网络连接是否正常,确保设备能够访问CloudDB服务。

  5. 代码逻辑错误:仔细检查代码逻辑,确保调用CloudDB的API时参数正确,并处理了可能的异常情况。

建议参考官方文档,确保每一步都按照指导进行。如果问题依旧,可以提供具体报错信息以便进一步排查。

回到顶部