Skip to content

Define the global regeneratorRuntime in @babel/runtime/regenerator#14581

Merged
nicolo-ribaudo merged 1 commit intobabel:mainfrom
nicolo-ribaudo:regenerator-globa
May 25, 2022
Merged

Define the global regeneratorRuntime in @babel/runtime/regenerator#14581
nicolo-ribaudo merged 1 commit intobabel:mainfrom
nicolo-ribaudo:regenerator-globa

Conversation

@nicolo-ribaudo
Copy link
Copy Markdown
Member

@nicolo-ribaudo nicolo-ribaudo commented May 24, 2022

Q                       A
Fixed Issues? Fixes #14576
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

Even if @babel/runtime was documented as being a pure set of helpers and the @babel/runtime/regenerator entry point exported the regeneratorRuntime helper, it also accientally used to define a regeneratorRuntime global due to its depenency on regenerator-runtime.

Many packages relied on this global being "accidentally" present due to something else in the dependencies tree loading @babel/runtime/regenerator. I'm annoyed by this, but let's restore the old (accidental and undocumented) behavior because I have already seen multiple repositories with this problem. We'll remove this legacy entry point in Babel 8.

Closes #14576.

@babel-bot
Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52006/

regeneratorRuntime = runtime;
} catch (accidentalStrictMode) {
if (typeof globalThis === "object") {
globalThis.regeneratorRuntime = runtime;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we remove the global definition behind the BABEL_8_BREAKING flag?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, this file isn't compiled.

module.exports = require("../helpers/regeneratorRuntime")();
// TODO(Babel 8): Remove this file.

const runtime = require("../helpers/regeneratorRuntime")();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is more appropriate to use var like runtime helpers, otherwise, this code needs to be compiled into es5 with babel self 👀

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sorry for that, we released the fix 2 minutes ago!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks 🚀

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Aug 25, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: @babel/runtime v7.18.0 cause a runtime "regeneratorRuntime is not defined" error

5 participants