isomorphic-git clone() TypeError: Cannot read property ‘bind’ of undefined

Tags: , , ,



I would like to use isomorphic-git with BrowserFS on Kintone (which does not support module imports).

I do not control the script tags but that’s how they are included in the resulting page :

<script src="https://unpkg.com/isomorphic-git@1.7.4"></script>
<script src="https://unpkg.com/browserfs"></script>

Then, I initialize BrowserFS to use the IndexedDB of the browser as its filesystem :

(new Promise((resolve,reject)=> {
  BrowserFS.getFileSystem({
    fs: "IndexedDB",
    options: {}
  }, function(error,fs) {
    if (error) {
      BrowserFS.configure({
        fs: "IndexedDB",
        options: {}
      }, function(error) {
        if (error) {
          reject(error)
        }
        const fs = BrowserFS.BFSRequire("fs")
        BrowserFS.BFSRequire("path")
        resolve(fs)
      })
    }
    resolve(BrowserFS.initialize(fs))
  })
})).then(fs => {
  ...

Finally, I use dynamic import for the isomorphic-git module:

  return import('https://unpkg.com/isomorphic-git@1.7.4/http/web/index.js').then(http => {
    window.http = http
    return true
  })
}).then(response => {
  ...

When I try to run a git clone command …

  return git.clone({
    fs,
    http,
    dir:stagingRoot,
    corsProxy: 'https://cors.isomorphic-git.org',
    url: repositoryURL.getValue(),
    ref: branch.getValue(),
    onAuth: url => {
      const auth = {
        username: username.getValue(),
        password: password.getValue(),
      }
      return auth
    },
    singleBranch: true,
    depth: 100
  })
}).then(response => {
  ...

I get the following TypeError :

Uncaught (in promise) TypeError: Cannot read property 'bind' of undefined
    at new u (isomorphic-git@1.7.4:formatted:157)
    at Module.<anonymous> (isomorphic-git@1.7.4:formatted:13793)
    at Generator.next (<anonymous>)
    at Qt (isomorphic-git@1.7.4:formatted:13757)
    at a (isomorphic-git@1.7.4:formatted:13771)
    at isomorphic-git@1.7.4:formatted:13776
    at new Promise (<anonymous>)
at Module.<anonymous> (isomorphic-git@1.7.4:formatted:13768)
at Module.re (isomorphic-git@1.7.4:formatted:13821)
at Module.ee (isomorphic-git@1.7.4:formatted:13782)

Any idea where it is coming from?

Answer

It was a simple problem of ordering in the script tag imports. The correct order was:

<script src="https://unpkg.com/browserfs"></script>
<script src="https://unpkg.com/isomorphic-git@1.7.4"></script>

I had other problems with BrowserFS, so I ended up reverting back to isomorphic-git provided lightning-fs …



Source: stackoverflow