'Fetching a github repo in react gives a "Module "stream" has been externalized for browser compatibility and cannot be accessed in client code" error

I am currently stuck with a problem trying to fetch github repo data using the octokit npm package. I use vite to run a dev server and when I try to make a request, the error that i get is:

Uncaught Error: Module "stream" has been externalized for browser compatibility and cannot be accessed in client code.

My React .tsx file looks like this:

import { Octokit, App } from 'octokit'
import React from 'react'

const key = import.meta.env.GITHUB_KEY
const octokit = new Octokit({
    auth: key
  })
await octokit.request('GET /repos/{owner}/{repo}', {
    owner: 'OWNER',
    repo: 'REPO'
  })
  
export default function Repos() {

  return (
    <>

    </>
  )
}

I have redacted the information for privacy purposes. If anyone knows how to resolve this issue with vite, please let me know!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source