Skip to content

"Error: 'return' outside of function" with async/await #869

@seungdols

Description

@seungdols

Current 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions