Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

363
Views
Cannot read properties of undefined (reading 'translate')

Now I am develop a google chrome extension plugin, I define a translate function in the my-ts.js file like this(all the code running in Google Chrome extension):

import * as tjs from 'translation.js'

export default {
  translate(queryObj) {
    const api = tjs[queryObj.api]
    return tjs[queryObj.api].translate(queryObj)
  },
  audio(queryObj) {
    return tjs[queryObj.api].audio(queryObj)
  }
}

when I use the function in another js file like this:

import {createServer} from 'connect.io';
import chromeCall from 'chrome-call';
import ts from '../public/my-ts';
import {write} from '../public/clipboard';
import ga from '../public/ga';

const server = createServer();

/**
 * fetch the translate result
 * @param {Query} queryObj
 * @param {Function} resolve
 */
export async function onGetTranslateResult( queryObj , resolve ) {
  queryObj.api = queryObj.api.toLowerCase()
  if(queryObj.api === 'googlecn') {
    queryObj.api = 'google'
  } else if (queryObj.api === 'google') {
    queryObj.api = 'google'
    queryObj.com = true
  }
  const {api} = queryObj;
  ga( 'send' , 'event' , 'translate' , api );
  try {
    resolve( await ts.translate( queryObj ) );
    ga( 'send' , 'event' , 'translate success' , api );
  }
  catch ( errorMsg ) {
    let error = errorMsg.message;
    if (errorMsg.code === 'NETWORK_TIMEOUT') {
      error = ''
    }
    if ( 'google' === queryObj.api && !queryObj.com ) {
      error += 'tips: make sure you are not open the proxy';
    }
    ga( 'send' , 'event' , 'translate failed' , api );
    resolve( { error, code: errorMsg.code } );
  }
}

shows error:

Cannot read properties of undefined (reading 'translate') 

why could not invoke the translate function? what should I do to make it work?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!