最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ES6 Uncaught TypeError: Object(...) is not a function - Stack Overflow

programmeradmin3浏览0评论

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?

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?

Share Improve this question edited Jul 17, 2018 at 7:33 deltaforce 5341 gold badge9 silver badges26 bronze badges asked Jul 17, 2018 at 6:35 izengodizengod 1,1565 gold badges17 silver badges42 bronze badges 5
  • 4 export default liab_config – Yury Tarabanko Commented Jul 17, 2018 at 6:38
  • 1 Should be import {liab_config} from './utils/kc-adapter' – Tan Duong Commented Jul 17, 2018 at 6:39
  • @TanDuong export default means I can import without {} – izengod Commented Jul 17, 2018 at 6:42
  • But I saw that you want to export object export default { liab_config }. – Tan Duong Commented Jul 17, 2018 at 6:46
  • yes that is the issue i guess – izengod Commented Jul 17, 2018 at 7:10
Add a comment  | 

2 Answers 2

Reset to default 10

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'

When you are accessing something like this

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

It means you are asking for the default export which must be written like

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

export { liab_config as default };

or like this

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

export default liab_config;

And if you don't want to make it default then pass it like

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

or

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

export { liab_config };

And access it like

import {liab_config} from './utils/kc-adapter'
发布评论

评论列表(0)

  1. 暂无评论