[英]twilio.AccessToken is “not a constructor” in TypeScript on Firebase Functions
I tried this with TypeScript on Firebase Functions: 我在Firebase Functions上使用TypeScript进行了尝试:
import * as twilio from 'twilio';
function generateToken(iden,room){
const token = new twilio.AccessToken(
envconf.twilio.sid,
envconf.twilio.apikey,
envconf.twilio.apisecret,
)
token.identity = iden;
const grant = new twilio.AccessToken.VideoGrant()
token.addGrant(grant);
return token.toJwt();
}
but I get this error in logs: 但我在日志中收到此错误:
TypeError: AccessToken is not a constructor
but this is like how they did it in the documentations . 但这就像他们在文档中所做的一样。 So maybe I should switch from TypeScript to Javascript?
所以也许我应该从TypeScript切换到Javascript?
I moved it to the Javascript, I get the same error. 我将其移至Javascript,但遇到相同的错误。 So this is not a TypeScript/Javascript compatibility issue.
因此,这不是TypeScript / Javascript兼容性问题。
I changed 我变了
const token = new twilio.AccessToken(
to 至
const token = new twilio.jwt.AccessToken(
and for some reason, it worked! 由于某种原因,它起作用了! I didn't post this update as an answer, because I don't understand why what they wrote in the example doesn't work and this works!
我没有发布此更新作为答案,因为我不明白为什么他们在示例中写的内容不起作用,而且行之有效!
Try to import twilio as : 尝试将twilio导入为:
const { twilio} = require('twilio');
Or 要么
import { twilio } from 'twilio'
这是文档中的错误,他们已将其修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.