what is the requireJs alternative?
I have a dependency called videojs that needs global/window.
however that doesn't exist and I found an issue (https://github.com/videojs/video.js/issues/5680#issuecomment-570120497) that shows a fix but it requires requirejs.
GitHub
videojs 7 requirejs js error: Script error for: global/window · Is...
Description package with requirejs make errors. Uncaught Error: Script error for: global/window Uncaught Error: Script error for: global/document my mainConfigFile like this requirejs.config({ path...
4 Replies
Hi @Just Simeon. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
In Nuxt, when dealing with libraries that need access to the global/window object (like videojs), you have several approaches to handle this without requiring RequireJS.
Client-side only initialization
The most common approach is to initialize such libraries only on the client side using the
onMounted
lifecycle hook:
Using a client plugin
For a more global solution, you can create a client-side plugin:
Using Nuxt Scripts module
For third-party scripts, you can use the Nuxt Scripts module which provides better control over script loading:
Nuxt Scripts provides features like lazy loading and better performance management for third-party scripts.
For Node.js polyfills
If your library specifically needs Node.js features in the browser, Nuxt offers an experimental feature called clientNodeCompat
that automatically polyfills Node.js imports in the client build:
For specific globals like Buffer, you would need to manually inject them:
Experimental Features - clientNodeCompat
Remember that when working with browser-specific APIs, you should always ensure they're only accessed in client-side code to avoid hydration mismatches or server-side errors.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@294593079812292609> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
I don't think this is the solution
I will wait for a human
This is my code: https://pastes.dev/RtlmBQJmmA
pastes | RtlmBQJmmA
A paste containing 74 lines of javascript.