Giter Club home page Giter Club logo

Comments (17)

leons1767 avatar leons1767 commented on June 28, 2024 1

Hi @AidanWelch,

I tried upgrading to v10.6.7 today. It is still the same error with Expo SDK 46.

from google-translate-api.

leons1767 avatar leons1767 commented on June 28, 2024 1

Just an update. I upgraded my app to Expo SDK 49, and the issue persists. The error is exactly the same.

I noticed that you were using axios in v10.4.2, and changed to fetch after that. fetch is not a standard function in react native, and it requires to be imported import {fetch} from 'react-native. Sorry that I didn't look into your codes until now. I accidentally discovered it while looking into all the dependencies that need to be upgraded for the Expo SDK upgrade.

from google-translate-api.

AidanWelch avatar AidanWelch commented on June 28, 2024

Hi, can you post the code?

from google-translate-api.

leons1767 avatar leons1767 commented on June 28, 2024

Hello @AidanWelch

Specific to my environment, I'm using Expo SDK46 android development build to run the codes. I found that I upgraded the package version accidentally, and downgrading it to v10.4.2 fixes it. It broke somewhere after v10.4.2. The latest version is broken as well.

         await translate(trText, { to: lang})
             .then((value) => trResult.push({ language: lang, text: value.text, fromLang: value.from.language.iso}))
             .catch((error) => console.log('translation error :', error))

Thanks to look into it.

from google-translate-api.

AidanWelch avatar AidanWelch commented on June 28, 2024

@leons1767

Can you check if the Fetch API is exposed in your environment?

from google-translate-api.

leons1767 avatar leons1767 commented on June 28, 2024

@AidanWelch

Fetch is working fine in my environment. I also have the below error with v10.5.4.

Possible Unhandled Promise Rejection (id: 1):
TypeError: (0 , _googleTranslateApiX.default) is not a function

{arguments: ["Possible Unhandled Promise Rejection (id: 1):\nTypeError: (0 , _googleTranslateApiX.default) is not a function"], logger: console}

from google-translate-api.

AidanWelch avatar AidanWelch commented on June 28, 2024

@leons1767

Can you try instead of doing

const translate = require('google-translate-api-x');
// Or
import translate from 'google-translate-api-x';

Instead doing

import { translate } from 'google-translate-api-x';
// or
const { translate } = require('google-translate-api-x');

I wonder if it's an issue with handling the default exports in that enviroment

from google-translate-api.

leons1767 avatar leons1767 commented on June 28, 2024

@AidanWelch

I tried before I opened the issue, it was not working.

from google-translate-api.

AidanWelch avatar AidanWelch commented on June 28, 2024

@leons1767 Can you try installing this in your project and running in your babel config: https://babeljs.io/docs/babel-preset-env

That fixes the issue for me.

from google-translate-api.

leons1767 avatar leons1767 commented on June 28, 2024

Hi @AidanWelch

I installed babel-preset-env, but what do I need to add in my babel.config.js? My current babel config in below.

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    env: {
      production: {
        plugins: ['react-native-paper/babel'],
      },
    },
    plugins: ['react-native-reanimated/plugin'],
  };
};

from google-translate-api.

AidanWelch avatar AidanWelch commented on June 28, 2024

After testing I actually ran into other issues with babel-preset-env so instead I started using @babel/plugin-proposal-private-methods which after installing you can add to your config like so:

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    env: {
      production: {
        plugins: ['react-native-paper/babel'],
      },
    },
    plugins: ['react-native-reanimated/plugin', ['@babel/plugin-proposal-private-methods', { loose: true }]],
  };
};

from google-translate-api.

leons1767 avatar leons1767 commented on June 28, 2024

@AidanWelch

Thanks for your time to support. I tried @babel/plugin-proposal-private-methods, added the exact babel config, and it's still giving the same error.

TypeError: (0 , _googleTranslateApiX.default) is not a function

from google-translate-api.

AidanWelch avatar AidanWelch commented on June 28, 2024

Hmm, I think it might be an issue with certain JS features not being supported in your version of expo or babel-preset-expo as it works perfectly fine with that config for me in expo 48.

from google-translate-api.

leons1767 avatar leons1767 commented on June 28, 2024

Unfortunately, I can't upgrade from Expo SDK46 to SDK48 yet, due to the dependency on RN0.71 in the SDK48. I guess I will have to do with v10.4.2 for now.

from google-translate-api.

AidanWelch avatar AidanWelch commented on June 28, 2024

Hmm, it may be possible to get it to work. You could also try adding @babel/plugin-proposal-object-rest-spread like the last plugin. And if that doesn't work there might be other babel config changes you can make to support newer JS features

from google-translate-api.

AidanWelch avatar AidanWelch commented on June 28, 2024

Should no longer be required in v10.6.7

from google-translate-api.

AidanWelch avatar AidanWelch commented on June 28, 2024

That's really weird because I have a react native project where I didn't have to import fetch but regardless, I'm glad you resolved it!

from google-translate-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.