Duplicate declaration error is thrown on `const` declaration in nested async functions
See original GitHub issueBug 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:
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:
- Created 5 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Definitely not “wontfix”. Wether the fix needs to be in Babel or Regenerator, it should be done.
Confirmed that this issue has been fixed and can not be reproduced on babel 7.4.0 now.