Skip to content

regeneratorRuntime required with @fluent/bundle even when not using the compat build #497

@elisehein

Description

@elisehein

Hello!

I'm not sure if this is me merely misunderstanding the docs, but I thought I'd raise anyway.

The README for @fluent/bundle mentions that if using the compat build, regenerator runtime must also be provided.

I'm seeing regeneratorRuntime required even though I'm not using the compat build.

Minimal working example:

package.json dependencies

"@babel/core": "^7.10.2",
"@babel/preset-env": "^7.10.2",
"@fluent/bundle": "^0.15.1",
"@fluent/react": "^0.12.0",
"babelify": "^10.0.0",
"browserify": "^16.5.1",
"react": "^16.13.1"

index.js

import { FluentBundle, FluentResource } from "@fluent/bundle";
import { ReactLocalization } from "@fluent/react";

function *generateBundle(locale) {
  const bundle = new FluentBundle(locale);
  bundle.addResource(new FluentResource("hello = Hola!"));
  yield bundle;
}

export default function l10n(locale) {
  return new ReactLocalization(generateBundle(locale));
}

l10n("en-GB");

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
  </head>

  <body>
    <script src="app.js"></script>
  </body>

</html>

Transpilation step

> node_modules/.bin/browserify index.js -t [ babelify --presets [ @babel/preset-env ] ] > app.js

Browser runtime error

Screenshot 2020-06-17 at 10 13 48

I can see regeneratorRuntime in the transpiled output:

var _bundle = require("@fluent/bundle");

var _react = require("@fluent/react");

var _marked = /*#__PURE__*/regeneratorRuntime.mark(generateBundle);

function generateBundle(locale) {
  var bundle;
  return regeneratorRuntime.wrap(function generateBundle$(_context) {
  // ...

This is easily fixed by me adding import regeneratorRuntime from "regenerator-runtime"; to the top of my file. But I suspect this isn't what I should be doing. Is it a case of out of date documentation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions