In my project, there is a custom third-party library (a single build file), which they have created using a couple of non-AMD and AMD files. And most of the properties are exposed directly to window objects. In our project as per the new requirement, we have to load this third-party library in asynchronous mode using requireJS. I tried with shim configuration but am getting an error from third party library saying that globals/window, globals/documents are needed.
This is the error we are encountering now
Could anyone please help me with this? Thanks in Advance!
It looks like your 3rd party library is video.js. Video.js was (see below) creating two global objects global/window
and global/document
which seem to be used for testing video.js on the server where there is no window or document.
You can see their definition here and then the import. If you're willing to edit the file (and stop video.js tests from working server-side) then that's a simple solution.
You said you didn't want to edit the library though, so let's look for other solutions. You could just go ahead and define them like so:
define('global/window', [], () => {
return window;
});
define('global/document', ['global/window'], (window) => {
return window.document;
});
Then load video.js:
require(['video.7.5.0.min.js'], (videojs) => {
window.videojs = videojs;
// any other initialization you want here
});
Also it might be helpful to know which version of video.js you're using. It appears this might have been fixed in 7.11.1 (in this PR) so there's a good chance that just upgrading to that version or later makes the problem go away.
There's a lot more discussion on this problem in this issue, but it appears to be closed due to the previously mentioned PR.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With