-
Notifications
You must be signed in to change notification settings - Fork 310
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
[BUG]: Uncaught ReferenceError: global is not defined #547
Comments
Running into this exact problem trying to use octokit from Nuxt 3 as well. |
Could you please test if this works correctly? import { Octokit } from '@octokit-next/core' |
Yes, that is working perfectly, thank-you! |
Having same issue in svelte. |
As a workaround, for vite, svelte and similar environments, load the package from import { Octokit } from "https://esm.sh/@octokit/[email protected]"; |
I was able to fix this in my project ( SvelteKit + Vite ) by adding this to the vite config after installing resolve: {
alias: {
'node-fetch': 'isomorphic-fetch',
},
}, Got the instructions from this StackOverflow thread, which also mentioned you might need to add: define: {
global: {}
} |
This will get resolved by octokit/request.js#586 |
What happened?
If you setup a fresh vite site, and run
npm i @octokit/core
then import it with:You will see in web dev-console:
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:
and call it like this:
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: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
The text was updated successfully, but these errors were encountered: