"Error: 'return' outside of function" with async/await
See original GitHub issueCurrent Behavior
Hello! Thank you for making this awesome tool.
By the way, an error occurred while testing to set up the project using this tool.
const puppeteer = require('puppeteer')
;(async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto('https://example.com')
await page.screenshot({ path: 'example.png' })
await browser.close()
})()
Error: 'return' outside of function (Note that you need plugins to import files that are not JavaScript)
at /Users/seungdols/dev/getGold/src/index.ts:3:24
1: const puppeteer = require('puppeteer')
2: ;(async () => {
3: const browser = await puppeteer.launch()
^
4: const page = await browser.newPage()
5: await page.goto('https://example.com')
Expected behavior
If you build using tsc, it is a code that builds normally.
Why this error message?
I can’t build a module of puppeteer example code.
I would like to know why the error occurs in a simple async/await code.
And I couldn’t understand exactly what the error message was saying, so I had to ask a question.
What exactly did I do wrong with this error message? I don’t know, can you change the message a little more kindly?
And can you guide me on how to solve this problem?
Your environment
OSX 10.15.6
Node 12.16.3
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Using await outside of an async function - Stack Overflow
I don't see where the problem is with that (maybe you already updated the repo)? If you refer to the isInLobby().then( … countPlayer().then...
Read more >How to use await outside of an async function in JavaScript
In this example, we will simply create a method and inside that method, we will return a promise which will actually use the...
Read more >How to use await outside of an async function in JavaScript
There are multiple ways to use the `await` operator outside of an `async` function - use a Node.js version higher than `16.12.0`, load...
Read more >"Error: 'return' outside of function" with async/await · Issue #869
I would like to know why the error occurs in a simple async/await code. And I couldn't understand exactly what the error message...
Read more >Async and Await - LearnHowToProgram.com
An async function allows us to write asynchronous code as if it were synchronous. This can make our code more concise. And while...
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 FreeTop 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
Top GitHub Comments
@agilgur5 Thank you for explaining in detail.
Actually, I tried to find this bug, but I still don’t understand the structure of the project, but you solved it.
Thanks to the kind explanation, it was an opportunity to understand the project more. It was really good for teaching.
thank you.😁
async-to-promises
has been replaced withbabel-plugin-polyfill-regenerator
in #795 and will be released in v0.14.0 soon. It will only pure polyfill generators fortargets
that need a polyfill according to yourbrowserslistrc
orpreset-env
targets
.For your specific purpose, since
puppeteer
runs in Node, I would recommend adding a.browserslistrc
: