New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"regeneratorRuntime is not defined" error with async and "useBuiltIns": "usage" #8829

Open
mrichmond opened this Issue Oct 8, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@mrichmond

mrichmond commented Oct 8, 2018

Bug Report

Current Behavior
I get a "regeneratorRuntime is not defined" error when using @babel/preset-env and "useBuiltIns": "usage" with a nested async arrow function in my React HOC.

Input Code
React Component JS - DeleteAsset.js

import React from 'react';
import { compose, withHandlers, setDisplayName } from 'recompose';
import { Button } from '@material-ui/core';

export default compose(
  setDisplayName('DeleteAsset'),
  withHandlers({
    onConfirm: ({ deleteImage, deleteVideo, id, type }) => async () => {
      if (type === 'image') await deleteImage(id);
      else if (type === 'video') await deleteVideo(id);
      console.log('ASSET DELETED');
    },
  }),
)(({ onConfirm }) => (<Button {...{ onClick: onConfirm }}>Delete</Button>));

Expected behavior/code
No regeneratorRuntime errors

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

{
  "devDependencies": {
    "@babel/cli": "7.1.2",
    "@babel/core": "7.1.2",
    "@babel/polyfill": "7.0.0",
    "@babel/preset-env": "7.1.0",
    "@babel/preset-react": "7.0.0",
    "webpack": "4.20.2",
    "webpack-cli": "3.1.2",
    "webpack-dev-server": "3.1.9"
  }
}

.babelrc

{
  "presets": [
    ["@babel/preset-env", {
      "targets": { "browsers": ["last 2 chrome versions"] },
      "useBuiltIns": "usage"
    }],
    "@babel/preset-react"
  ]
}

Environment

  • @babel/cli version: 7.1.2
  • @babel/core version: 7.1.2
  • @babel/polyfill version: 7.0.0
  • @babel/preset-env version: 7.1.0
  • Node version: 10.11.0
  • NPM version: 6.4.1
  • Yarn version: 1.10.1
  • webpack version: 4.20.2
  • webpack-cli version: 3.1.2
  • webpack-dev-server version: 3.1.9
  • How you are using Babel: loader (webpack)

Possible Solution
If I switch to "entry" mode and add the polyfill to my webpack entry, then the regeneratorRuntime error is no longer present.

example .babelrc config: "useBuiltIns": "entry"
example webpack.config.js config: entry: ['@babel/polyfill', './src/index.js'],,

It seems that "entry" is a less optimal solution than "usage" for the "useBuiltIns" parameter. I believe this indicates a possible bug with the "usage" feature of "useBuiltIns" with Babel 7 @babel/preset-env.

Additional context/Screenshots
image

@babel-bot

This comment has been minimized.

Show comment
Hide comment
@babel-bot

babel-bot Oct 8, 2018

Collaborator

Hey @mrichmond! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

Collaborator

babel-bot commented Oct 8, 2018

Hey @mrichmond! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment