Skip to content

Parcel, how to fix the `regeneratorRuntime is not defined` error

I run into this problem in a project using Babel as soon as I added an async function, but the problem is the same for any recent JavaScript feature:

Babel, used by Parcel, generates a polyfill, but to avoid this error you need to also load the regenerator-runtime runtime.

One solution: add to the top of your main JavaScript file:

import 'regenerator-runtime/runtime'

Parcel will include this package by default, increasing the size of 25KB.

The solution that is the most efficient in terms of codebase is adding the browserslist property to your package.json.

For example:

"browserslist": [
  "last 1 Chrome version"
]

For testing is good enough. To support multiple browsers:

"browserslist": [
  "last 3 and_chr versions",
  "last 3 chrome versions",
  "last 3 opera versions",
  "last 3 ios_saf versions",
  "last 3 safari versions"
]

or also:

"browserslist": [
  "since 2017-06"
]

You have to add a version that’s recent enough to support async/await, so Babel does not try to add a polyfill.

Check all the valid values here: https://github.com/browserslist/browserslist


→ Get my JavaScript Beginner's Handbook

→ I wrote 17 books to help you become a better developer:

  • C Handbook
  • Command Line Handbook
  • CSS Handbook
  • Express Handbook
  • Git Cheat Sheet
  • Go Handbook
  • HTML Handbook
  • JS Handbook
  • Laravel Handbook
  • Next.js Handbook
  • Node.js Handbook
  • PHP Handbook
  • Python Handbook
  • React Handbook
  • SQL Handbook
  • Svelte Handbook
  • Swift Handbook
...download them all now!

Also, JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025

Bootcamp 2025

Join the waiting list