Parse-sdk-js: ReferenceError: regeneratorRuntime is not defined

Created on 11 Jan 2019  路  7Comments  路  Source: parse-community/Parse-SDK-JS

Using parse through CDN or npm install parse@version works

I get the following error ReferenceError: regeneratorRuntime is not defined

If I try to run get the bleeding edge in a node project

npm install parse-community/Parse-SDK-JS.git#master --save

or

build it myself and copy parse.min.js from the dist folder into a simple html file.

I don't know much about babel to fix the issue

help wanted needs investigation resolved

Most helpful comment

Facing the same issue with [email protected]

https://github.com/parse-community/Parse-SDK-JS/blob/master/gulpfile.js#L18 specifies @babel/plugin-transform-runtime configuration option:

regenerator: false

That instructs babel to transpile async functions into a code that assumes existence of globally defined regeneratorRuntime.

When you start to use the SDK in a project that does not define a global regeneratorRuntime you'll bump into the exception.

Workarounds

There are some workarounds, but appropriate solution highly depends on your project's specific configuration>

  1. Manually include regeneratorRuntime
    Use https://www.npmjs.com/package/regenerator-runtime and make sure the following code is executed before Parse is initialized:
import regeneratorRuntime from 'regenerator-runtime/runtime';
window.regeneratorRuntime = regeneratorRuntime;
  1. Use babel to try and inject the polyfill
    Use @babel/polyfill together with @babel/preset-env + customize the option useBuildIns to inject required polyfills. That's quite tricky, though and very implicit.

  2. Use [email protected]

For maintainers

If there's no specific reason to use this option here, I would suggest to set it to true. That will cause babel to use @babel/runtime/regenerator instead of a global variable, which is much easier to set up (as described in generatorAliasing)

All 7 comments

Also have this issue, did you find a solution?

I haven't you can try playing around with babel to see if you can get it to work

Facing the same issue with [email protected]

https://github.com/parse-community/Parse-SDK-JS/blob/master/gulpfile.js#L18 specifies @babel/plugin-transform-runtime configuration option:

regenerator: false

That instructs babel to transpile async functions into a code that assumes existence of globally defined regeneratorRuntime.

When you start to use the SDK in a project that does not define a global regeneratorRuntime you'll bump into the exception.

Workarounds

There are some workarounds, but appropriate solution highly depends on your project's specific configuration>

  1. Manually include regeneratorRuntime
    Use https://www.npmjs.com/package/regenerator-runtime and make sure the following code is executed before Parse is initialized:
import regeneratorRuntime from 'regenerator-runtime/runtime';
window.regeneratorRuntime = regeneratorRuntime;
  1. Use babel to try and inject the polyfill
    Use @babel/polyfill together with @babel/preset-env + customize the option useBuildIns to inject required polyfills. That's quite tricky, though and very implicit.

  2. Use [email protected]

For maintainers

If there's no specific reason to use this option here, I would suggest to set it to true. That will cause babel to use @babel/runtime/regenerator instead of a global variable, which is much easier to set up (as described in generatorAliasing)

Why does this error appear? Everything was working fine to me last week and now I have this issue too.

Same here - I uninstalled [email protected] and installed [email protected] --exact and it's back to normal

Revert to 2.1.0 is the workaround for now.

For newbies to the Parse JS SDK (like me) I reverted to the 2.1.0 level of the parse.min.js script by retrieving it from:

https://npmcdn.com/[email protected]/dist/parse.min.js

placed it in a local js directory and updated the script tag to refer to it instead of the npmcdn server.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

simpleshadow picture simpleshadow  路  6Comments

fdidron picture fdidron  路  4Comments

Jonarod picture Jonarod  路  6Comments

bezi picture bezi  路  4Comments

ryanemax picture ryanemax  路  7Comments