Function 谷歌云函数:require(…)不是一个函数
我正在尝试部署Google云功能,我只是在index.js文件中添加了初始要求:Function 谷歌云函数:require(…)不是一个函数,function,api,google-cloud-platform,google-cloud-functions,speech,Function,Api,Google Cloud Platform,Google Cloud Functions,Speech,我正在尝试部署Google云功能,我只是在index.js文件中添加了初始要求: // Import the Google Cloud client libraries const nl = require('@google-cloud/language')(); const speech = require('@google-cloud/speech')(); const storage = require('@google-cloud/storage')(); 但我在部署时收到以下消息:
// Import the Google Cloud client libraries
const nl = require('@google-cloud/language')();
const speech = require('@google-cloud/speech')();
const storage = require('@google-cloud/storage')();
但我在部署时收到以下消息:
Detailed stack trace: TypeError: require(...) is not a function
这只发生在@google cloud/speech和@google cloud/language模块上,@google cloud/storage模块作为一个函数加载良好(我通过评论前两个模块进行了测试)
任何建议都将不胜感激
Borrigan谷歌云函数是nodejs模块,因此语法与nodejs语法相同 关于你的问题: 你必须写作
const storage = require('@google-cloud/storage');
(每个语句末尾不带()
因此,正确的声明是:
// Import the Google Cloud client libraries
const nl = require('@google-cloud/language');
const speech = require('@google-cloud/speech');
const storage = require('@google-cloud/storage');
我希望这会有所帮助。它告诉您,您需要的任何东西都不是函数,因此不能用() 如果你看这里: 您会看到一个具有多个类返回函数的服务对象正在被返回,因此您应该像这样设置它:
const nl = require('@google-cloud/language');
const language = new nl.LanguageServiceClient();
关于这个Github,googlecloud的
v2包中有一些变化
因此,您可以导入以下包:
const {Storage} = require('@google-cloud/storage');
const storage = new Storage({
// config...
});
遵循以下新语法:
const {Storage} = require('@google-cloud/storage');
const googleCloudStorage = new Storage({
projectId: 'your-project-id',
keyFilename: 'path-to-json-config-file'
});
有什么消息吗?面对同样的问题,我发现至少语言包使用了环境变量Shere是github发行版的链接欢迎使用Stack Overflow并感谢您的帮助!不过,我建议您多花一点时间来创建您的答案。添加一些细节来帮助澄清代码的作用以及为什么要这样做,这将有助于让您的答案脱颖而出。