Skip to content

SyntaxError: Unexpected token < in JSON at position 0 #47

@pixysadfee

Description

@pixysadfee

I used a simple code to translate strings using @iamtraction/google-translate

    const translate = require('@iamtraction/google-translate');
    
    module.exports = function({ string, from, to }) {
    
    	return new Promise(resolve => { 
    
    		run();
    
    		async function run() {
    		    try {
    		        const res = await translate(string, { from, to });
    				return resolve(res.text);
    		    } catch(err) {
    		        console.log(err);
    		        run();
    		    }
    		}
    
    	});
    
    }

and I used the above function as:

    const bigTranslation = await googleTranslator({ string: 'It looks like we’ll have to stand', from: 'en', to: 'es' });
    
    return console.log(bigTranslation);

It worked perfectly till hours ago but now I get this error:

SyntaxError: Unexpected token < in JSON at position 0
at JSON.parse ()
at consumeEnd (C:\inetpub\wwwroot\Server\node_modules\undici\lib\api\readable.js:237:20)
at BodyReadable. (C:\inetpub\wwwroot\Server\node_modules\undici\lib\api\readable.js:219:7)
at BodyReadable.emit (node:events:513:28)
at BodyReadable.emit (C:\inetpub\wwwroot\Server\node_modules\undici\lib\api\readable.js:66:18)
at endReadableNT (node:internal/streams/readable:1359:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Why This is happening ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions