-
Notifications
You must be signed in to change notification settings - Fork 27
Description
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 using npm run build and npm 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.js
I searched all my modules and only Pexels have dependency on 'isomorphic-fetch'.
...
function Ph(e) {
if (!e || typeof e !== "string")
throw new TypeError(
"An API key must be provided when initiating the Pexels client."
);
return { typeCheckers: _h, photos: xh(e), videos: Ch(e), collections: Eh(e) };
}
require("isomorphic-fetch"); // here
const Nh = Ph("qaxLvqCpYIxuOSlbBG6BYEoZup3UZpB8a7PZ2JGEiWO7CPzmmQbQDGp7"),
Lh = async (e) => ({
values: e.query ? e : {},
errors: e.query
? {}
: { query: { type: "required", message: "Input required" } },
});
...
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.