error appears in chrome extension when importing selenium-webdriver in javascript

I am building a web extension to run automated tests using javascript, when installing and importing selenium-webdriver the extension crash showing the following message:

Uncaught TypeError: Cannot read properties of undefined (reading 'O_CREAT')
    at ./node_modules/selenium-webdriver/node_modules/tmp/lib/tmp.js 

this error appears for selenium-webdriver version 4.7.0

I tried older versions, till I reach version 4.3.0, then it showed a different error

Uncaught ReferenceError: Buffer is not defined
    at ./node_modules/selenium-webdriver/node_modules/ws/lib/constants.js

Has anybody faced this before? and how can I solve it?

I searched everywhere for this error, but no solution. I could not figure out why it is showing this error. I tried deleting the node modules and re-installing, clearing the cache then reinstalling, installing many package that might be related to it but no luck at all.

Read more here: Source link