【发布时间】:2021-04-29 22:06:22
【问题描述】:
我一直在尝试将谷歌翻译 API 与我的 redux 应用程序集成,但我似乎无法让它工作。我已经下载了我的私钥并将它们保存到本地文件路径。当我运行example code 时,它运行良好。当我尝试在我的异步 redux thunk 中调用 translate 函数时出现问题,如下所示:
const projectId = '{my google cloud project id goes here}'
const keyFilename = '{the full path to my private key goes here}'
const translate = new Translate({projectId, keyFilename});
export const addPairs = createAsyncThunk(
'pairs/addPairs',
async () => {
let [translations] = await translate.translate('hello world', 'en');
return translations
}
)
每当我使用dispatch 调用此函数时,它总是返回此错误:
fs.createReadStream is not a function
我似乎无法弄清楚为什么会这样,我已经尝试搜索任何其他解决方案,但似乎没有人以前有过类似的用例......任何帮助都是非常感谢!
【问题讨论】:
标签: javascript npm google-cloud-platform google-translate google-translation-api