最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Translation failed TypeError: google_translate_api_x__WEBPACK_IMPORTED_MODULE_0__ is not a function - Stack Overflo

programmeradmin0浏览0评论

I attempted to run this code for my translation web app created from react:

import translate from 'google-translate-api-x';

export async function translateText(text, sourceLang, targetLang) {
  try {
    const response = await translate(`${text}`, {
      from: `${sourceLang}`, 
      to: `${targetLang}`, 
      autoCorrect: true
    });

    // Extract the translated text from the response
    return response.text;
  } catch (error) {
    console.error("Error during translation:", error);
    throw error;
  }
}

It keeps giving me the error: Translation failed TypeError: google_translate_api_x__WEBPACK_IMPORTED_MODULE_0__ is not a function

I read the API README and copied the way that they have used the function and didn't get the same result. I think this problem may lie in export async function I am a JavaScript/React beginner so I do not have much knowledge on how to solve the issue.

发布评论

评论列表(0)

  1. 暂无评论