我正在尝试部署Google Cloud功能,我首先将初始需求添加到我的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')();
但是在部署时我收到以下消息:
Detailed stack trace: TypeError: require(...) is not a function
这只发生在@ google-cloud / speech和@ google-cloud / language模块中,@ google-cloud / storage模块作为一个函数正好加载(我通过评论前两个来测试)。
任何建议将不胜感激。
Borrigan
参考这个Github comment,google-cloud
v2包有一些变化
所以你导入包如:
const {Storage} = require('@google-cloud/storage');
const storage = new Storage({
// config...
});
Google云功能是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');
我希望这有帮助。
它告诉你,你需要的不是函数,因此不能用()调用
如果你看这里:https://www.npmjs.com/package/@google-cloud/language#using-the-client-library你看到一个具有多个类返回函数的服务对象正在被返回,所以你应该像这样设置它:
const nl = require('@google-cloud/language');
const language = new nl.LanguageServiceClient();