eduardoborges / use-mask-input

✏️ A react Hook for build elegant input masks. Compatible with React Hook Form
https://npmjs.com/package/use-mask-input
333 stars 19 forks source link

next.js - self is not defined #9

Closed ciruz closed 1 year ago

ciruz commented 1 year ago

Hey nice work,

I try to use use-mask-inputwith react-hook-form and next.js, sadly I get this reference error, since Web-APIs are not available on the server side.

ReferenceError: self is not defined
    at eval (webpack-internal:///(sc_client)/./node_modules/use-mask-input/node_modules/inputmask/dist/inputmask.js:10:3)
    at (sc_client)/./node_modules/use-mask-input/node_modules/inputmask/dist/inputmask.js

Any plans to make it compatible with next.js?

Thank you

PS: If somebody wants to use it , but has the same error, just load your form with next/dynamic and ssr: false.

eduardoborges commented 1 year ago

Well, a input mask need directly for Web API... So... The code mask must run on client side.

I will thing how to make work seamlessly on Nextjs. I'm accepting PR/suggestions to. <3

ciruz commented 1 year ago

Hey @eduardoborges,

nice, thanks. I think if you first check if window is available, it should be fixed and compatible. Something like:

if (typeof window !== 'undefined') {
  // your code
}
eduardoborges commented 1 year ago

Uh make sense lol 😂

eduardoborges commented 1 year ago

Hey @eduardoborges,

nice, thanks. I think if you first check if window is available, it should be fixed and compatible. Something like:

if (typeof window !== 'undefined') {
  // your code
}

Hey, i make experiments, but... this problem happen when i need to load inputmask. We need to find a way to load condicionaly :/

ciruz commented 1 year ago

Sounds like an issue with inputmask itself then, or?

eduardoborges commented 1 year ago

Sounds like an issue with inputmask itself then, or?

Exactly.

jlucaso1 commented 1 year ago

Hi @eduardoborges, I think in the new version of inputmask this is resolved: https://github.com/RobinHerbots/Inputmask/pull/2663 Can you confirm this and update?

eduardoborges commented 1 year ago

Hi @eduardoborges, I think in the new version of inputmask this is resolved: RobinHerbots/Inputmask#2663 Can you confirm this and update?

Hey, not solve the problem, but apear another. I opened an PR for solve that.

RobinHerbots/Inputmask#2709

eduardoborges commented 1 year ago

Hey guys! good news! Latest version of beta of inputmask solves the problems with NextJs.

Upgrate to 3.2.0

@jlucaso1 @ciruz

ciruz commented 1 year ago

Thank you very much

lobatolais commented 1 year ago

Thank you so much, @eduardoborges! <3 It may be worth updating the documentation to include the information that compatibility with Next.js is now supported.

eduardoborges commented 1 year ago

Thank you so much, @eduardoborges! <3 It may be worth updating the documentation to include the information that compatibility with Next.js is now supported.

Yeah! I will do this!

Im working on new simplified API 👀 and fresh new and more compleat documentation. 😻