masroorejaz / react-simple-captcha

A very simple and powerful captcha for ReactJS
40 stars 19 forks source link

Doesn't work in React 18 #23

Closed hidaytrahman closed 1 year ago

hidaytrahman commented 1 year ago

Tried to load both parser.


Module not found: Error: Can't resolve 'buffer' in 'learn/node_modules/react-html-parser/node_modules/htmlparser2/lib'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
    - add a fallback 'resolve.fallback: { "buffer": require.resolve("buffer/") }'
    - install 'buffer'
If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "buffer": false }
masroorejaz commented 1 year ago

I haven't tested it with React 18 as of now.

But what I have Googled so far I think the issue lies somewhere else. Try installing these two npm and let me know if this resolves your issue:

npm install assert --save npm install buffer --save

hidaytrahman commented 1 year ago

Thank you @masroorejaz. Is there any plan to remove these dependencies

hidaytrahman commented 1 year ago

Closing this with the implementation of React 18 (hooks)

import {
  loadCaptchaEnginge,
  LoadCanvasTemplate,
  LoadCanvasTemplateNoReload,
  validateCaptcha,
} from "react-simple-captcha";

loadCaptchaEnginge(6) (You can change 6 to the number of captcha characters you want) in useEffect()

  useEffect(() => {
    loadCaptchaEnginge(6);
  }, []);
masroorejaz commented 1 year ago

Thank you @masroorejaz. Is there any plan to remove these dependencies

You are most welcome. Will see in the future.