cocos creator 使用腾讯云函数报错

首先是3.7.3版本的creator 按照腾讯云函数的文档, 引入SDK后就直接报错。
用import cloudbase from “@cloudbase/js-sdk/app” 引入,报错 [Scene] Error: Error: 不支持目录导入
image
用const tcb = require("@cloudbase/node-sdk");引入,报错 [Scene] Error: Cannot find module ‘@cloudbase/node-sdk’
image

然后换成2.4.11可以正常引入 云函数SDK,web调试(浏览器)一切正常。
但是用模拟器调试就继续报错。

没有人知道吗?

官方 都没有答案吗?

import { _decorator, Component, Node } from ‘cc’;

const { ccclass, property } = _decorator;

import cloud from ‘./libs/faas-web-sdk/dist/index.js’;

@ccclass(‘Alipay’)

export class NewComponent extends Component {

async start() {

   

    var self = this;

    /**

    my.request({

        url: 'https://env-00jx3shfuxva.dev-hz.cloudbasefunction.cn/helloworld',

        method: 'POST',

        dataType: 'json',

        success: function (res) {

            self.getComponent(cc.Label).string = res.data.message

        }

      });

      */

      const sdk = new cloud.Cloud({

        //在环境概览中获取

        endpoint: 'https://env-00jx49rafua2.api-hz.cloudbasefunction.cn',

         //在环境概览中获取 AK

        secretId: 'xxx',

        //在环境概览中获取 SK

        secretKey: 'xxx',

        //填写自己的APPID

        appId: 'xxxx',

        //填写自己的环境ID

        envId: 'env-00jx49rafua2',

      });

      try {

        const res = await sdk.callFunction({

          name: 'cocos',

        });

        console.log("---" + res.result.message);

        self.getComponent(cc.Label).string = res.result.message

       

        console.log('调用结果', res);

      } catch(e) {

        console.error('调用失败', e);

      }

   

}

update(deltaTime: number) {

   

}

}

image

这里调用 支付宝云开发云函数的方式,是可以使用的 ,可以参考