Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: fetch is not defined #20

Closed
Film-Worachai opened this issue Dec 25, 2022 · 2 comments
Closed

ReferenceError: fetch is not defined #20

Film-Worachai opened this issue Dec 25, 2022 · 2 comments

Comments

@Film-Worachai
Copy link

/root/***/node_modules/google-translate-api-x/lib/defaults.cjs:9
        requestFunction: fetch,
                         ^

ReferenceError: fetch is not defined
    at Object.<anonymous> (/root/***/node_modules/google-translate-api-x/lib/defaults.cjs:9:19)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/root/***/node_modules/google-translate-api-x/lib/translate.cjs:2:29)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
@AidanWelch
Copy link
Owner

Addressed in d0c1543

If you are using an environment that doesn't have the Fetch api exposed you can pass any function that emulates the behavior of the Fetch api such as node-fetch or even a simple wrapper around axios. This is as simple as

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

const res = await translate('gato', {from: 'es', to: 'en', requestFunction: fetch});

console.log(res.text); // => 'cat'

@AidanWelch AidanWelch pinned this issue Dec 25, 2022
@Film-Worachai
Copy link
Author

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants