Skip to content
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

Prevent regeneratorRuntime is not defined errors by defensively copying targets (preventing @babel/helper-compilation-targets from mutating targets) #345

Merged

Conversation

fivetanley
Copy link
Member

@fivetanley fivetanley commented May 29, 2020

Babel 7.10.0 introduced a change that mutates the targets object passed into @babel/helper-compilation-targets. Since ember-cli caches the value of config/targets.js on the Project,
that means any subsequent calls to ember-cli-babel would lose @babel/preset-env options defined in targets if the ember-cli babel was
included again anywhere else in the tree (which it usually is due to addons depending on ember-cli-babel). This would sometimes result in a regeneratorRuntime is not defined error for addons like Ember Concurrency that use ECMAScript features like generator functions or async functions, because the addon would not be compiled against the appropriate browsers list (or other @babel/preset-env options) because @babel/helper-compilation-targets mutated it away. This would happen usually in development or test, if limiting the targets used in development , which has been the default in Ember CLI for a while now. regenerator was not included in the host app because it was using the appropriate browserlist, and so ember-maybe-import-regenerator did not include regenerator runtime in the build. Ember concurrency then would get compiled without the appropriate targets, and would get compiled down to IE9/regenerator runtime instead of using native generator/async await syntax.

As a workaround, we can copy the targets object before passing it to @babel/helper-compilation-targets as a workaround until the regression is fixed upstream in babel.

The yarn.lock changes were made to bring in babel 7.10.0 so we could test this change.

Babel 7.10.0 [introduced a change that mutates the `targets` object passed into [`@babel/helper-compilation-targets`](babel/babel#11500).
Since [ember-cli caches the value of `config/targets.js` on the Project](https://github.com/ember-cli/ember-cli/blob/master/lib/models/project.js#L271-L289),
that means any subsequent calls to ember-cli-babel would lose `@babel/preset-env` options defined in `targets` if the ember-cli babel was
included again anywhere else in the tree (which it usually is due to addons depending on ember-cli-babel). This would sometimes result in a `regeneratorRuntime is not defined` error for addons like Ember Concurrency that use ECMAScript features like generator functions or async functions, because the addon would not be compiled against the appropriate `browsers` list (or other `@babel/preset-env` options) because `@babel/helper-compilation-targets` mutated it away. This would happen usually in development or test, if [limiting the targets used in development](https://www.rwjblue.com/2017/10/30/async-await-configuration-adventure/#limit-targets-locally), which has been the [default in Ember CLI for a while now](ember-cli/ember-cli@7798114).

As a workaround, we can copy the `targets` object before passing it to `@babel/helper-compilation-targets` as a workaround until the regression is [fixed upstream in babel](babel/babel#11648).
Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you again @fivetanley!

@rwjblue rwjblue merged commit 38db30c into emberjs:master May 30, 2020
@rwjblue rwjblue added the bug label May 30, 2020
@rwjblue rwjblue changed the title [bugfix] defensively copy targets so @babel/helper-compilation-targets can't mutate targets Prevent regeneratorRuntime is not defined errors by defensively copying targets (preventing @babel/helper-compilation-targets from mutating targets) May 30, 2020
HeroicEric added a commit to HeroicEric/ember-cli-babel that referenced this pull request Jul 3, 2022
This removes a workaround that was added for a bug in
`babel-helper-compilation-targets` that was fixed upstream and is
included in the version that is required by this addon.

The bugfix in `babel-helpers-compilation-targets` was included in
`7.10.2`

`[email protected]` began requiring a version of
`babel-helpers-compilation-targets` that includes the bugfix since
`v7.21.0`.

This addon has had a depenedency on `7.10.2`

- [Original bugfix workaround PR](emberjs#345)
- [`[email protected]` Release notes](https://github.com/babel/ember-cli-babel/blob/master/CHANGELOG.md#v7210-2020-06-12)
- [`[email protected]` Release notes](https://github.com/babel/babel/blob/main/CHANGELOG.md#v7102-2020-05-30)
HeroicEric added a commit to HeroicEric/ember-cli-babel that referenced this pull request Jul 3, 2022
This removes a workaround that was added for a bug in
`babel-helper-compilation-targets` that was fixed upstream and is
included in the version that is required by this addon.

The bugfix in `babel-helpers-compilation-targets` was included in
[`v7.10.2`](https://github.com/babel/babel/releases/tag/v7.10.2)

`ember-cli-babel` began requiring a version of
`babel-helpers-compilation-targets` that includes the bugfix since
[`v7.21.0`](https://github.com/babel/ember-cli-babel/releases/tag/v7.21.0)

---

- [Original bugfix workaround PR](emberjs#345)
- [Dependency upgrade PR](emberjs#354)
- [`[email protected]` Release notes](https://github.com/babel/ember-cli-babel/releases/tag/v7.21.0)
- [`[email protected]` Release notes](https://github.com/babel/babel/releases/tag/v7.10.2)
bertdeblock pushed a commit to HeroicEric/ember-cli-babel that referenced this pull request Nov 3, 2022
This removes a workaround that was added for a bug in
`babel-helper-compilation-targets` that was fixed upstream and is
included in the version that is required by this addon.

The bugfix in `babel-helpers-compilation-targets` was included in
[`v7.10.2`](https://github.com/babel/babel/releases/tag/v7.10.2)

`ember-cli-babel` began requiring a version of
`babel-helpers-compilation-targets` that includes the bugfix since
[`v7.21.0`](https://github.com/babel/ember-cli-babel/releases/tag/v7.21.0)

---

- [Original bugfix workaround PR](emberjs#345)
- [Dependency upgrade PR](emberjs#354)
- [`[email protected]` Release notes](https://github.com/babel/ember-cli-babel/releases/tag/v7.21.0)
- [`[email protected]` Release notes](https://github.com/babel/babel/releases/tag/v7.10.2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants