gatsby: "regeneratorRuntime is not defined" throwing this error with plugins

When I’m trying to include data source as contentful, JSON it’s throwing this error regeneratorRuntime is not defined I don’t know why is that ? When I’m simply just including this to plugins as array and recompile the whole project it’s not compiling and throwing this error. I don’t understand why is that happening.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 31 (19 by maintainers)

Commits related to this issue

Most upvoted comments

I did this and it helped somewhat, but what really solved it was adding:

exports.modifyBabelrc = ({ babelrc }) => ({
  ...babelrc,
  ...process.env.NODE_ENV !== 'development' && {
    plugins: babelrc.plugins.concat(['transform-regenerator', 'transform-runtime']),
  },
});

Don’t forget to also install:

    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-polyfill": "^6.26.0",
    "babel-runtime": "^6.26.0",

Works great now with async Apollo queries on https://spacechop.com

btw, tell me if you want a 3 month free test coupon on SpaceChop! 😄

Same issue here. Getting regeneratorRuntime is not defined

For anyone coming across this in more recent history than 2018, it appears that the gatsby APIs used to accomplish this have changed. I was able to get this working with the following in gatsby-node.js:

exports.onCreateBabelConfig = ({ actions }) => {
  if (process.env.NODE_ENV !== 'development') {
    actions.setBabelPlugin({
      name: '@babel/plugin-transform-regenerator',
      options: {},
    });
    actions.setBabelPlugin({
      name: '@babel/plugin-transform-runtime',
      options: {},
    });
  }
};

Yeah. We can reopen if it’s still causing trouble.

@timbrandin awesome that helped alot but to run npm run build, I also need to: npm i babel-plugin-transform-runtime or yarn add babel-plugin-transform-runtime

I added babel-runtime to all packages so hopefully this error won’t show up anymore.

Try upgrading gatsby-cli to the latest version.