下面的代码片段来自watson音调分析器文档。问题:当我粘贴代码并运行代码时,它运行得非常好。但是,当我将它粘贴到另一个云函数中时,它说明找不到ibm-watson/auth的模块。不确定为什么它表现不同??
通常我保存在函数main (params){}下。然而,另一个云函数是异步函数,它有(Require Promise)的代码。不确定是哪里出了问题,还是出了什么问题?
const ToneAnalyzerV3 = require('ibm-watson/tone-analyzer/v3');
const { IamAuthenticator } = require('ibm-watson/sdk');
const toneAnalyzer = new ToneAnalyzerV3({
version: '2017-09-21',
authenticator: new IamAuthenticator({
apikey: 'apikey',
}),
serviceUrl: 'url',
});
const text = 'Team, I know that times are tough! Product '
+ 'sales have been disappointing for the past three '
+ 'quarters. We have a competitive product, but we '
+ 'need to do a better job of selling it!';
const toneParams = {
toneInput: { 'text': text },
contentType: 'application/json',
};
toneAnalyzer.tone(toneParams)
.then(toneAnalysis => {
console.log(JSON.stringify(toneAnalysis, null, 2));
})
.catch(err => {
console.log('error:', err);
});
}发布于 2021-03-21 15:24:40
在使用IBM Cloud Functions时,请注意不同的runtime environments及其包含的模块和包。如果遇到找不到某个模块的错误,
https://stackoverflow.com/questions/66686225
复制相似问题