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

javascript - exporting a default async function is not defined in current file - Stack Overflow

programmeradmin0浏览0评论

The following works perfectly:

export default function x () {
  return 'hello world'
}

export function y () {
  return x()
}

console.log(y())

However this does not work:

export default async function x () {
  return 'hello world'
}

export function y () {
  return x()
    .then(console.log)
}

y()

When the default function is async for some reason x is not defined.

The following works perfectly:

export default function x () {
  return 'hello world'
}

export function y () {
  return x()
}

console.log(y())

However this does not work:

export default async function x () {
  return 'hello world'
}

export function y () {
  return x()
    .then(console.log)
}

y()

When the default function is async for some reason x is not defined.

Share Improve this question edited Jan 23, 2017 at 1:04 loganfsmyth 162k31 gold badges346 silver badges258 bronze badges asked Dec 17, 2016 at 22:08 ThomasReggiThomasReggi 59.6k97 gold badges258 silver badges459 bronze badges 3
  • Do you need a polyfill of some kind for this? I remember some kind of babel polyfill solving something like this. Also what happens if you remove "default". – Tim Consolazio Commented Dec 17, 2016 at 22:12
  • 1 @TimConsolazio If I remove it, it works perfectly fine. – ThomasReggi Commented Dec 17, 2016 at 22:15
  • I'm using the babel latest plugin. – ThomasReggi Commented Dec 17, 2016 at 22:15
Add a ment  | 

1 Answer 1

Reset to default 4

Looks like this is a known issue inside babel project: https://github./babel/babel/issues/3786

发布评论

评论列表(0)

  1. 暂无评论