-
Notifications
You must be signed in to change notification settings - Fork 331
[BUG]: Uncaught ReferenceError: global is not defined #547
Copy link
Copy link
Closed
Labels
Type: BugSomething isn't working as documentedSomething isn't working as documented
Description
What happened?
If you setup a fresh vite site, and run npm i @octokit/core then import it with:
import { Octokit } from '@octokit/core'You will see in web dev-console:
Uncaught ReferenceError: global is not defined
at index.mjs:657:16
It appears to come from node-fetch, which should not be running in this web-context.
(judging by the code near this in the console)
In my top-level index.html, I can do this:
<script type="module">
import { Octokit } from "https://cdn.skypack.dev/octokit";
window.Octokit = Octokit
</script>and call it like this:
const octokit = new window.Octokit({ auth })and it works fine, but this is not really standard frontend library usage (should be able to import it, directly.)
I recommend using cross-fetch which ponyfills more correctly on node environments and works correctly on frontend:
import fetch from 'cross-fetch'It uses node-fetch, but wraps it correctly.
Versions
node 17.6.0, 18.5.0
vite 4.0.4
@octokit/core: 4.1.0
Relevant log output
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type: BugSomething isn't working as documentedSomething isn't working as documented
Type
Projects
Status
✅ Done
