Vue.js and ES7: ReferenceError: RegeneratorRuntime not defined

Viewed 2293

I want to use async/await syntax in my vue App. When doing so, I get this error: ReferenceError: regeneratorRuntime is not defined

I already found multiple solutions pointing me in this direction of user adi518 on github: https://github.com/adi518/vue-facebook-login-component/issues/17

As far as syntax goes, I'd probably try this, at the top of my main.js, because as far as responsibility goes, that's where you usually initialize libraries and polyfills (App.vue just seems unrelated).

So,

npm install --save regenerator-runtime
And then:

import "regenerator-runtime";

I successfully ran the npm installation. Also, my main.js now has this added to the imports: import 'regenerator-runtime';

I can build the project, but still the runtime regeneratorRuntime doesnt work, i get the same referenceError. What else can I do or what am I missing?

1 Answers

I solved my issue by installing core-js and regenerator-runtime

npm i -S core-js@latest regenerator-runtime@latest

and then import it at the beginning of your main file, in my case main.js because it is declared on the entry key of Webpack.

// Recomendation of babeljs (https://babeljs.io/docs/en/babel-polyfill)
import 'core-js/stable'; // only stable feature also is possible with only `core-js`
import 'regenerator-runtime/runtime'; // To ensure that regeneratorRuntime is defined globally

I hope this will be useful. Regards.

Related