IBM Cloud Functions:找不到"ibm-watson/auth"软件包 [英] IBM Cloud Functions: Can't find 'ibm-watson/auth' package

查看:59
本文介绍了IBM Cloud Functions:找不到"ibm-watson/auth"软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 IBM Cloud函数 IBM Watson Discovery 请求一些结果.此处有一个很好的GitHub存储库关于如何调用此存储库.但是,在功能中设置动作的方式中,出现错误,消息为找不到模块'ibm-watson/auth'.我了解消息内容,但是如果您查看GitHub存储库,就会发现我执行了完全相同的步骤.我的IBM Cloud功能代码是:

I'm using IBM Cloud functions for requesting some results from IBM Watson Discovery. There is a very good GitHub repo here about how can we invoke this. However, on the way of setting the action in the function an error with message Cannot find module 'ibm-watson/auth' occurs. I understand what the message says, but if you check the GitHub repo, you see that I apply exactly the same steps. My IBM Cloud function code is:

case 'doc_info':
            var user_input = params.user_input;
            const watson = require('ibm-watson/sdk');
            const { CloudantV1 } = require('@cloudant/cloudant');
            const DiscoveryV1 = require('ibm-watson/discovery/v1');
            const { IamAuthenticator } = require('ibm-watson/auth');
            //const { IamAuthenticator } = require('ibm-cloud-sdk-core');

            try {
                const discovery = new DiscoveryV1({                 // Initializing Discovery
                    version: '2020-11-24',
                    authenticator: new IamAuthenticator({
                        apikey: params.apiKeyDisco,
                    }),
                    serviceUrl: params.urlDisco,
                });

                const cloudant = new CloudantV1({                   // Initializing CloudantV1
                    authenticator: new IamAuthenticator({
                        apikey: params.apiKeyCloudant
                    })
                });
                cloudant.setServiceUrl(params.urlCloudant);
                 
                 // ...
                 return {
                   answer: "Simple test"
                 };
                
            } catch (err) {
                console.log(err)
                return Promise.reject({
                  statusCode: 500,
                  headers: { 'Content-Type': 'application/json' },
                  body: { message: err.message },
                });
            }
            break;

即使从 ibm-cloud-sdk-core 包中调用 IamAuthenticator ,我也尝试过,但是错误是 IamAuthenticator不是构造函数.我们该如何解决呢?

I've tried even with calling IamAuthenticator from the ibm-cloud-sdk-core package, but then the error is IamAuthenticator is not a constructor. How can we solve this?

推荐答案

在此处查看

See here for the runtime environments available in IBM Cloud Functions. Depending on the Node.js version, there are different versions of the IBM Watson SDK. As stated in the docs, the Node.js 12 runtime has the newer SDK with the IAM Authentication functionality you are looking for. The Node.js 10 runtime has the V4.x IBM Watson SDK.

因此,您需要使用以下旧方法(已记录)进行身份验证,或升级到Node.js 12运行时.

Thus, you need to either use the old (documented) way of authenticating, or move up to the Node.js 12 runtime.

如果您使用旧的用户名/密码身份验证,并且仅具有IAM API密钥,请使用 iamapikey 作为用户名,并使用API​​密钥作为密码.

If you use the old username / password authentication and only have an IAM API key, use iamapikey as username and the API key as password.

这篇关于IBM Cloud Functions:找不到"ibm-watson/auth"软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆