I have tried to migrate a CRA to vite. One remaining obstacle is a dependency of a dependency that has this code:
var requestFrame = (function () {
var window = this
var raf = window.requestAnimationFrame ||
//...and so on and so forth
})()
this
is undefined
and the first thing it tries to invoke (requestAnimationFrame
) throws. The page, depending on a dependency that depends on this seems to have worked fine before so I’m suspecting that something can be configured in vite to fix this, but i’m not sure what to be looking for.
2
Answers
What seems to work for me and my particular case is to patch this one particular package with
patch-package
. I've made a diff that changesI have been able to do a fresh install after removing
/node_modules
and i've been able to build this inside docker. I guess i was always able to build it, it's just that now it actually works and does not crash some page.The issue arises because in
strict mode
(which Vite uses by default), this in an IIFE (Immediately Invoked Function Expression) is undefined. This was not the case in older versions of JavaScript or non-strict mode, where this would refer to the global object (e.g., window in browsers).I will suggest another solution, Just check:
here the
var window = this
So that it will work, please check