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

Buffer not set correcly #1753

Open
domlen2003 opened this issue Apr 16, 2023 · 5 comments
Open

Buffer not set correcly #1753

domlen2003 opened this issue Apr 16, 2023 · 5 comments

Comments

@domlen2003
Copy link

Setup

Browser, bundled with Vite (SvelteKit)

Reproduce

Create try a (browser based) git clone as per docs using ESM import syntax.

Behaviour

The following error occurs:

ReferenceError: Buffer is not defined
    at StreamReader._next (index.js:2450:7)
    at async StreamReader._init (index.js:2493:19)
    at async StreamReader.read (index.js:2420:24)
    at async read (index.js:6754:22)
    at async parseRefsAdResponse (index.js:6805:17)
    at async GitRemoteHTTP.discover (index.js:6996:26)
    at async _fetch (index.js:7640:22)
    at async _clone (index.js:8017:42)
    at async Object.clone (index.js:8140:12)

Hot-Fix

This problem is fixed when adding the following lines:

import {Buffer} from "buffer";

self.Buffer = Buffer;

Real-Fix

Investigate why Buffer is not defined/not imported properly when using the described setup.

@jcubic
Copy link
Contributor

jcubic commented Apr 16, 2023

I think that the problem is with your setup and with Vite not with the library. But I'm not sure how to setup Vite properly so it works like in the browser. Since you run the NodeJS version of isomorphic-git from the browser.

I'm not Vite expert, but you can try to figure out for yourself why Vite reads the NodeJS version and how to setup it up properly. But this is just my guess why Vite fails.

@aral
Copy link

aral commented Sep 20, 2023

If I remember correctly, Vite uses esbuild and this is an esbuild issue… right found it: vitejs/vite#2785

evanw/esbuild#1626

@jcubic
Copy link
Contributor

jcubic commented Sep 20, 2023

@aral thanks for the reference.

@ninjadev64
Copy link

Hey, I'm using SvelteKit/Vite too :)

But yeah,

import { Buffer } from "buffer";
globalThis.Buffer = Buffer;

seems to be a working solution.

@jcubic
Copy link
Contributor

jcubic commented Oct 27, 2023

There was an issue #698 but now when @wmhilton left the project there is no one that would remove Buffer from code.

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

No branches or pull requests

4 participants