Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'regeneratorRuntime is not defined' #452

Open
philipp-tailor opened this issue Oct 22, 2020 · 2 comments · May be fixed by #453
Open

'regeneratorRuntime is not defined' #452

philipp-tailor opened this issue Oct 22, 2020 · 2 comments · May be fixed by #453

Comments

@philipp-tailor
Copy link

philipp-tailor commented Oct 22, 2020

As of #296, vue-cli-plugin-apollo is broken when using it in environments which don't include regenerator-runtime. The reason that this has gone mostly unnoticed (except for #386) seems to be that nearly everyone transpiles their bundles in ways which conceal the fact.

What causes the issue?

The usage of async/await in graphql-client/src/index.js.

The file is transpiled with build:graphql-client, which basically just uses @babel/preset-env. This preset includes IE11 and adds calls to regenerator-runtime, presuming that it's globally available.

Showcase:

  • REPL of async function with default env preset: includes calls to the non-defined regeneratorRuntime.
  • REPL of async function with default env preset minus IE11: does not include calls to regeneratorRuntime.

How to resolve the issue?

I am no expert on distributing packages nowadays. I see two simple possible ways to remove the issue:

  • Install regeneratorRuntime and import it in graphql-client/src/index.js. The dist output is then able to run as distributed, even in IE11 (but probably bloated in size). Edit: it seems that another / the recommended option for a library would be to add @babel/plugin-transform-runtime to .babelrc. That would result in such output.
  • Change the babel config to exclude IE11 as transpile target. The dist output would be able to run on its own, except for browsers not supporting async/await.
    One could also consider building / shipping two versions, one modern bundle output, and one maximum compatible commonjs output.

I am happy to open PRs in any of the directions described above.

philipp-tailor added a commit to bird-labs/vue-cli-plugin-apollo that referenced this issue Oct 22, 2020
@philipp-tailor philipp-tailor linked a pull request Oct 22, 2020 that will close this issue
@franciscolourenco
Copy link
Contributor

This problem is reproducible when enabling --modern mode for example.

@johannespfrang
Copy link

johannespfrang commented Aug 19, 2024

Some time ago I've published vue-cli-plugin-apollo-without-regenerator-runtime to. Feel free to use/pin that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants