Uncaught ReferenceError: regeneratorRuntime is not defined
See original GitHub issueLibrary Affected: workbox-webpack-plugin
Browser & Platform: Was found on Chrome v51
Bug: I am using this plugin like so:
new GenerateSW({
babelPresetEnvTargets: ["last 4 versions", "safari >= 7"],
cacheId: 'sw',
cleanupOutdatedCaches: true,
clientsClaim: true,
exclude: [/\.map$/, /stats\.json$/],
inlineWorkboxRuntime: true,
runtimeCaching: [
{
urlPattern: /^https:\/\/fonts\.googleapis\.com.*/,
handler: 'StaleWhileRevalidate',
},
],
skipWaiting: true,
sourcemap: false,
swDest: 'sw.js',
}),
This error is coming through into the browser console:
Uncaught ReferenceError: regeneratorRuntime is not defined
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (5 by maintainers)
Top Results From Across the Web
How to fix regeneratorRuntime is not defined?
I have ran into a problem, the error is regeneratorRuntime is not defined while working with React and Parcel bundler.
Read more >Babel 6 regeneratorRuntime is not defined
I did not need babel-runtime to get async await working. Is that correct? Edit: I'm running the code server side. :) – GijsjanB....
Read more >ReferenceError regeneratorRuntime is not defined #9849
I'm building an SSR template, and when I use @babebl/register and then execute webpack (config), the system reported an error.
Read more >Parcel, how to fix the `regeneratorRuntime is not defined` ...
I run into this problem in a project using Babel as soon as I added an async function, but the problem is the...
Read more >Blank Admin Page: regeneratorRuntime is not defined ...
Uncaught ReferenceError : regeneratorRuntime is not defined ... Still experiencing the issue while deploying with Heroku, no idea how to fix ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
When you set
babelPresetEnvTargets
, there’s a single transpilation performed, and a single service worker file output. You can think of it as meeting the requirements of the “lowest common denominator” based on yourbabelPresetEnvTargets
configuration.If your
babelPresetEnvTargets
configuration includes a browser that doesn’t have support for generators, then the single service worker file that’s output will include code that referencesregeneratorRuntime
. IfregeneratorRuntime
isn’t available (which it wouldn’t be if you’re using a transpilation configured by Workbox), then the code will fail to run on any browser—it’s failing on modern browsers that have generator support because there’s now a dependency on the missingregeneratorRuntime
.As suggested, you can either perform your own transpilation after Workbox produces a service worker file, and in that transpilation, add in support for the
regeneratorRuntime
(check thebabel
documentation for exactly how you’d do that). Alternatively, you could ensure that you set Workbox’sbabelPresetEnvTargets
to only include browsers that have generator support, and the service worker file that Workbox creates should work across all of those browsers.I’m leaving this issue open because it’s definitely something that we could help prevent from happening—I think Workbox could conditionally add the
regeneratorRuntime
to the service workers it transpiles without incurring a larger bundle size when it’s not needed. But what I’m offering in the meantime is some workarounds that should address your issue.Hey all. Sorry for not updating this for a while.
@phil-w, the
babelPresetEnvTargets
setting is available when you’re using theGenerateSW
plugin.If you’re using the
InjectManifest
plugin, then any Babel plugins from the parent compilation is applied to the child compilation that outputs your service worker.@mycolaos, if you could point me to a GitHub project or some other code archive that includes a full setup which reproduces the problem you’re seeing, I’ll dive into it and tell you what needs to be configured where, and potentially see how those changes could be upstreamed to the source projects.
In general, one option that wasn’t mentioned yet is that if you want to pull in the regenerator runtime into your service worker, it can be explicitly loaded from, e.g., the unpkg CDN (or using a local copy that you maintain). The mechanism for loading it varies depending on which webpack plugin you’re using:
GenerateSW
: addimportScripts: ['https://unpkg.com/regenerator-runtime@0.13.7/runtime.js']
to your Workbox configuration.InjectManifest
: addimportScripts('https://unpkg.com/regenerator-runtime@0.13.7/runtime.js');
to the top of yourswSrc
file.Again, you can replace those URLs with a copy of the
regenerator-runtime
code served from a local URL if you’d rather not rely on a CDN.