RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.4k stars 2.17k forks source link

Reference error when server side rendering #2661

Closed splashdust closed 2 years ago

splashdust commented 2 years ago

Everything works well when only running in the browser, but the following error prevents the application from starting up when rendering on the server side:

node_modules/inputmask/dist/inputmask.js:13
}(self, (function() {
^
ReferenceError: self is not defined

self is only availble in a browser context, so it fails on the server.

Inputmask version 5.0.7

RobinHerbots commented 2 years ago

Have a try with version 5.0.8-beta.47

On Tue, Nov 1, 2022 at 4:32 PM Joacim Magnusson @.***> wrote:

Everything works well when only running in the browser, but the following error prevents the application from starting up when rendering on the server side:

node_modules/inputmask/dist/inputmask.js:13 }(self, (function() { ^ ReferenceError: self is not defined

self is only availble in a browser context, so it fails on the server.

Inputmask version 5.0.7

— Reply to this email directly, view it on GitHub https://github.com/RobinHerbots/Inputmask/issues/2661, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACNX3ZN2S4YCRMJMN3DVR3WGEZXTANCNFSM6AAAAAARUFNPEU . You are receiving this because you are subscribed to this thread.Message ID: @.***>

splashdust commented 2 years ago

Have a try with version 5.0.8-beta.47

Thank you for replying! I tried upgrading to 5.0.8-beta.47, but am still getting the error:

inputmask.js:13
}(self || this, (function() {
  ^

ReferenceError: self is not defined

I see that it is now supposed to use this if self is falsy. However, since self is not defined at all in this context, the result is still a reference error.

The code would need to look something like this to work:

}(typeof self !== 'undefined' ? self : this, (function() {
splashdust commented 2 years ago

Added a PR for a proposed solution: #2663

RobinHerbots commented 2 years ago

@splashdust ,

Thx !!!