git-repository icon indicating copy to clipboard operation
git-repository copied to clipboard

ReferenceError: regeneratorRuntime is not defined

Open dschnare opened this issue 8 years ago • 3 comments
trafficstars

Seems to be an error when trying to run the open() method.

at Function.open (....../node_modules/git-repository/lib/Repository.js:198:14)

This is line 198 in lib/Repository.js:

return regeneratorRuntime.async(function open$(context$2$0) {

Node: 6.9.1 Other: Using like: node -r ts-node/register some-module-that-uses-git-repository

dschnare avatar Jul 13 '17 16:07 dschnare

I actually can't find regeneratorRuntime defined anywhere in the compiled/generated files.

dschnare avatar Jul 13 '17 16:07 dschnare

I resolved this by finding that babel-polyfill is actually required to be pre-required first.

See: https://stackoverflow.com/questions/33527653/babel-6-regeneratorruntime-is-not-defined-with-async-await#33527883

Workaround:

node -r ts-node/require -r babel-polyfill some-module-that-uses-git-repository

This should be capable of being run right in Node without needing anything else.

dschnare avatar Jul 13 '17 17:07 dschnare

How you might fix this is depending on regenerator-runtime.

npm install regenerator-runtime -S

Then in src/Repository.js

/**
 * Copyright © 2015 Konstantin Tarkus.  All rights reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.txt file in the root directory of this source tree.
 */

import { join, resolve } from 'path';
// Expose regeneratorRuntime() as global function so that the
// async functions (after being compiled) can run in plain Node
import 'regenerator-runtime/runtime'
import cp from './utils/cp';
import fs from './utils/fs';

class Repository {

dschnare avatar Jul 13 '17 17:07 dschnare