question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duplicate declaration error is thrown on `const` declaration in nested async functions

See original GitHub issue

Bug Report

Current Behavior babel throws

Duplicate declaration "foo" (This is an error on an internal node. Probably an internal error.)

Input Code

  • REPL or Repo link if applicable:

https://babeljs.io/repl#?babili=false&browsers=Chrome >%3D 45%2Clast 2 Firefox versions%2Cie >%3D 9%2CEdge >%3D 12%2CiOS >%3D 9%2CAndroid >%3D 4%2Clast 2 ChromeAndroid versions&build=&builtIns=false&spec=false&loose=false&code_lz=BQQwzgngdgxgBMAlHAvAPjgbwFBzw8aeJVDHffGAeyjABc4AzKq1OAFgCYBuXfAX0RI-g4XiA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=&prettier=false&targets=&version=7.0.0-beta.34&envVersion=7.0.0-beta.34

Note: you have to manually add @babel/transform-regenerator 7.0.0 plugin since the url does not synchronize plugin selections.

(async () => {
    (async () => {
      const foo = 42;
    })()
  })()
  

Expected behavior/code Compiled as regenerator calls

Babel Configuration (.babelrc, package.json, cli command)

module.exports = {
    plugins: [
        "@babel/transform-regenerator"
    ]
}

Environment

  • Babel version(s): v7.0.0
  • Node/npm version: Node 10
  • OS: macOS 10.14
  • Monorepo no
  • How you are using Babel: cli

Possible Solution Workaround: add await to the nested async function.

Additional context/Screenshots Possibly related: #8525

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
nicolo-ribaudocommented, Nov 1, 2018

Definitely not “wontfix”. Wether the fix needs to be in Babel or Regenerator, it should be done.

1reaction
JLHwungcommented, May 22, 2019

Confirmed that this issue has been fixed and can not be reproduced on babel 7.4.0 now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does var allow duplicate declaration but why does const ...
If you try to redeclare it, it's not a normal behavior. Either you pick an other identifier, or you change the value (if...
Read more >
Async/Await Error Handling - Beginner JavaScript - Wes Bos
Go into our playground and copy the async-await.html file and rename it to async-await-error-handling.html . Go and delete everything except for these two ......
Read more >
Strict mode - JavaScript - MDN Web Docs
JavaScript's strict mode is a way to opt in to a restricted variant of JavaScript, thereby implicitly opting-out of "sloppy mode".
Read more >
A tour of the Dart language
For more information, see The main() function. var: A way to declare a ... from the initializing expression of a const declaration, like...
Read more >
CoffeeScript
Major new features in CoffeeScript 2 include async functions and JSX. ... Since CoffeeScript takes care of all variable declaration, it is not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found