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

docs: Module "buffer" has been externalized for browser compatibility #1680

Open
milahu opened this issue Nov 24, 2022 · 3 comments · May be fixed by #1683
Open

docs: Module "buffer" has been externalized for browser compatibility #1680

milahu opened this issue Nov 24, 2022 · 3 comments · May be fixed by #1683

Comments

@milahu
Copy link

milahu commented Nov 24, 2022

when i run isomorphic-git in a browser, i get this error

Module "buffer" has been externalized for browser compatibility. Cannot access "buffer.Buffer" in client code

with vite bundler, this is fixed by adding the buffer package

import { Buffer } from 'buffer'
globalThis.Buffer = Buffer

vitejs/vite#2785

lets add this to readme?

https://github.com/isomorphic-git/isomorphic-git#getting-started

If you're using isomorphic-git in the browser, you'll need something that emulates the fs API.

full code

// fix: Module "buffer" has been externalized for browser compatibility. Cannot access "buffer.Buffer" in client code
import { Buffer } from 'buffer'
globalThis.Buffer = Buffer

import h from 'hyperscript';
import * as git from "isomorphic-git"
import http from 'isomorphic-git/http/web'
import LightningFS from "@isomorphic-git/lightning-fs"

var button = h("button", "git clone");
button.onclick = async () => {
  const fs = new LightningFS('fs')
  const dir = '/test-clone'
  git.clone({
    fs,
    http,
    dir,
    url: 'https://github.com/isomorphic-git/lightning-fs',
    corsProxy: 'https://cors.isomorphic-git.org'
  }).then(console.log)
  // FIXME undefined
}
document.body.appendChild(button);
@jcubic
Copy link
Contributor

jcubic commented Nov 24, 2022

I think that README is not a good place for this. I believe there was a FAQ somewhere but I can't find a link on the website.

@milahu
Copy link
Author

milahu commented Nov 25, 2022

https://github.com/isomorphic-git/isomorphic-git#getting-started
https://isomorphic-git.org/docs/en/quickstart
https://isomorphic-git.org/docs/en/faq

maybe it "just works" with other bundlers (webpack, browserify, ...)
because they polyfill the buffer module by default
but in vite, i have to do it manually

@jcubic
Copy link
Contributor

jcubic commented Nov 25, 2022

There was a PR #925 to remove Buffer dependency but it was not finished someone wanted to take over the work but it seems that he didn't.

If you think that README is the best place for this you can update it with a section about Vite.

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.

2 participants