Also seeing this issue, using the window object before checking if it exists breaks our server side render of a react app.
I've fixed the problem doing something like this (React code):
state = {
inputMask: null,
}
componentWillUnmount() {
this.state.inputMask.remove(this.inputRef)
}
setInputRef = ref => {
import(`inputmask`)
.then(module => {
this.inputRef = ref
this.setState({inputMask: module}, () => {
this.state.inputMask(YOUR_MASK).mask(this.inputRef)
})
})
}
@kolyabokov ,
@TigerC10 ,
@augustolima ,
What would be the best approach for this? I created window.js to deal with this in the future. So maybe I can fix this now.
Would checking if window isn't defined requiring window through jsdom?
if (typeof define === "function" && define.amd)
define(function () {
return window || new (eval("require('jsdom')")('')).window;
});
else if (typeof exports === "object")
module.exports = window || new (eval("require('jsdom')")('')).window;
Bump. Still an issue.
My workaround:
const Inputmask=(typeof(window)!="undefined")?require("inputmask"):{};
Most helpful comment
Also seeing this issue, using the window object before checking if it exists breaks our server side render of a react app.