Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 Uncaught TypeError: Object(...) is not a function

I'm returning a Promise from this function

const liab_config = () => {
  return axios.get(`${config.server_url}/fetch_config_liab`);
}

export default { liab_config }

And trying to handle the Promise inside another file

import liab_config from './utils/kc-adapter'

function set_liab_config(){
  liab_config().then((response) => {
    if(response.data.success){
      let { kc_config_liab } = response.data;
      return kc_config_liab['auth-server-url'];
    }
    else
      return null;
  }).catch(ex => 
    console.log(ex));
  }

Here I'm getting the error as:

Uncaught TypeError: Object(...) is not a function

on line liab_config().then((response). What could be the reason?

like image 619
izengod Avatar asked Jul 17 '18 06:07

izengod


1 Answers

You're default-exporting an object literal. You want to use either a named export

const liab_config = …;
export { liab_config as liab_config }
// shorter:
const liab_config = …;
export { liab_config }
// or just:
export const liab_config = …;

with

import { liab_config } from './utils/kc-adapter'

or a default export

const liab_config = …;
export { liab_config as default }
// or just:
default export const liab_config = …;
// or without the local name:
default export …;

with

import liab_config from './utils/kc-adapter'
like image 70
Bergi Avatar answered Oct 25 '22 17:10

Bergi