-
Notifications
You must be signed in to change notification settings - Fork 29
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
Uncaught ReferenceError with require("isomorphic-fetch") #49
Comments
Have the exact same isssue here |
Apparently its a issue with vite build in production. I've used this quick fix for now in main.tsx: |
I'm facing the same issue, but I'm not using TypeScript (and I'm unfamiliar with it). Would such a workaround be possible in jsx? edit: Ended up dropping the wrapper altogether. fetch() works just fine. |
@arwin4 Did you fix it? Im having the same issue |
I wasn't able to fix this error. For my project, I just needed one simple API call, so I ended up using the native fetch(). This is my implementation, hope it helps. const imageRequest = await fetch(
`https://api.pexels.com/v1/search?query=${query}&per_page=15&page=1`,
{
headers: {
Authorization: APIkey,
},
},
).then((response) => response.json()); |
My guess is that one of the dependencies uses commonJS. Another issue had the fix that worked for me, which was adding this to my
|
having the same issue in Nuxt3 |
Same issue suggestions drop off the client and make your own wrapper like this:
|
Adding it solved my problem; thank you very much
|
I am using the Pexels library with React and TypeScript, built on Vite, for my pet project.
While I start the app on the development server
npm run dev
, everything works as expected. However, when I try to run the build version usingnpm run build
andnpm run preview
, I encounter an error:Uncaught ReferenceError: require is not defined at index-e209a5d9.js:10314:1
The error is caused by the line
require("isomorphic-fetch");
in the file ../dist/assets/index-e209a5d9.jsI searched all my modules and only Pexels have dependency on 'isomorphic-fetch'.
Based on how it looks, it seems that the
require("isomorphic-fetch");
line does nothing, so I tried deleting it. After removing this line, the program started working and fetch data.However, I don't know what should i do next to prevent this error for next builds.
The text was updated successfully, but these errors were encountered: