You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
regeneratorRuntime required with @fluent/bundle even when not using the compat build #497
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?
In #472 I removed the compat builds altogether and in #483 I removed the mention of regeneratorRuntime from the README. I was planning to continue the build system cleanups in #480 but I hit a roadblock. I needlessly put off releasing new versions of all @fluent packages until I can figure how to fix it. I'm sorry about that, I'll work on releasing new versions next week.
The main motivation for removing the compat builds in #472 was that today's build tools are capable of transpiling dependencies which means we should be able to provide a single version of a @fluent package written in fairly modern JS, and the build tool will transpile it if needed.
In your example, I assume that browserify is transpiling all code, including the @fluent/bundle dependency. So even if you're not using the compat build, you end up with a transpiled version of @fluent/bundle anyways; hence the need for the regeneratorRuntime. Am I understanding this right?
In your example, I assume that browserify is transpiling all code, including the @fluent/bundle dependency. So even if you're not using the compat build, you end up with a transpiled version of @fluent/bundle anyways; hence the need for the regeneratorRuntime. Am I understanding this right?
I'm indeed using browserify, but as far as I'm aware, the transforms (babelify with @babel/preset-env) do not automatically apply to files in node_modules, so the expectation is that any packages imported from node modules are already transpiled, and are just included in the bundle as-is. So that still leaves me a bit confused about regeneratorRuntime popping up in the transpiled code...
About that piece of doc, IIRC that was supposed to mean:
If you're not using the compat builds, you need a fancy new browser, and anything just slightly old will break in all kinds of ways.
If you want older browsers, the compat builds get you far, but we didn't include the regenerators, as you might need them elsewhere, and then your transpiled js would get unnecessarily large.
So you need generators either way, but the non-compat builds break on a lot more than just that.
so the expectation is that any packages imported from node modules are already transpiled, and are just included in the bundle as-is. So that still leaves me a bit confused about regeneratorRuntime popping up in the transpiled code...
Could it be that browserify (or babelify?) uses the regeneratorRuntime to transpile the *generateBundle(locale) generator function in your index.js?
In fact, @fluent/bundle doesn't even use yield nor async functions; even transpiled, it wouldn't require the runtime to be present for legacy browsers. OTOH the runtime would be needed for transpiled versions of packages like @fluent/dom and @fluent/react.
@stasm Indeed, thanks, that looks like it's the crux of it!
To test, when I replace *generateBundle with a vanilla JS function that only pretends to return a generator, I no longer need to import regeneratorRuntime:
function generateBundle(locale) {
const bundle = new FluentBundle(locale);
bundle.addResource(bundle.addResource(new FluentResource("hello = Hola!"));
let result = {};
result[Symbol.iterator] = () => {
return {
next: () => {
return {
done: true,
value: bundle
};
}
};
};
return result;
}
I'll close this issue now, thanks all for helping me investigate.
Activity
stasm commentedon Jun 17, 2020
Thank you for a comprehensive issue report!
In #472 I removed the
compatbuilds altogether and in #483 I removed the mention ofregeneratorRuntimefrom the README. I was planning to continue the build system cleanups in #480 but I hit a roadblock. I needlessly put off releasing new versions of all@fluentpackages until I can figure how to fix it. I'm sorry about that, I'll work on releasing new versions next week.The main motivation for removing the
compatbuilds in #472 was that today's build tools are capable of transpiling dependencies which means we should be able to provide a single version of a@fluentpackage written in fairly modern JS, and the build tool will transpile it if needed.In your example, I assume that
browserifyis transpiling all code, including the@fluent/bundledependency. So even if you're not using thecompatbuild, you end up with a transpiled version of@fluent/bundleanyways; hence the need for theregeneratorRuntime. Am I understanding this right?elisehein commentedon Jun 17, 2020
I'm indeed using browserify, but as far as I'm aware, the transforms (
babelifywith@babel/preset-env) do not automatically apply to files innode_modules, so the expectation is that any packages imported from node modules are already transpiled, and are just included in the bundle as-is. So that still leaves me a bit confused aboutregeneratorRuntimepopping up in the transpiled code...Pike commentedon Jun 17, 2020
About that piece of doc, IIRC that was supposed to mean:
If you're not using the compat builds, you need a fancy new browser, and anything just slightly old will break in all kinds of ways.
If you want older browsers, the compat builds get you far, but we didn't include the regenerators, as you might need them elsewhere, and then your transpiled js would get unnecessarily large.
So you need generators either way, but the non-compat builds break on a lot more than just that.
elisehein commentedon Jun 17, 2020
@Pike Thanks, that makes sense!
stasm commentedon Jun 17, 2020
Could it be that
browserify(orbabelify?) uses theregeneratorRuntimeto transpile the*generateBundle(locale)generator function in yourindex.js?In fact,
@fluent/bundledoesn't even useyieldnorasync functions; even transpiled, it wouldn't require the runtime to be present for legacy browsers. OTOH the runtime would be needed for transpiled versions of packages like@fluent/domand@fluent/react.elisehein commentedon Jun 17, 2020
@stasm Indeed, thanks, that looks like it's the crux of it!
To test, when I replace
*generateBundlewith a vanilla JS function that only pretends to return a generator, I no longer need to importregeneratorRuntime:I'll close this issue now, thanks all for helping me investigate.